doctorx0079 doctorx0079 - 1 month ago 19
Android Question

Menu item always goes in the overflow menu in Android

I have a menu icon for my ActionBar, but it always goes into the overflow menu no matter what I do. I want it to show up as an icon and not go into the overflow menu.

Here is my menu_daily_selfie.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/camera_button"
android:icon="@android:drawable/ic_menu_camera"
android:title="Camera"
app:showAsAction="always"/>
</menu>


I'm using the appcompat library. What gives? Seems like this should work.

Here is my onCreateOptionsMenu:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_daily_selfie, menu);
return true;
}

Answer

My main activity extends ListActivity since it uses a ListView

Then you are not using appcompat-v7 properly. Either:

  • Switch to inheriting from AppCompatActivity, and manage your own ListView, or

  • Stop using appcompat-v7, and switch your menu resource to use android:showAsAction instead of app:showAsAction