I can't get the Action Bar to display my action items. They all show up in the overflow menu. I have pasted all the relevant code below. Can anyone see my problem?
From Activity:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.viewer_menu, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_download:
return true;
case R.id.menu_star:
return true;
case R.id.menu_report:
return true;
case android.R.id.home:
// app icon in action bar clicked; go home
finish();
return true;
}
return false;
}
From Manifest:
<activity android:name=".CustomActivity"
android:label="">
From values-v11 folder (themes.xml)
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo">
</style>
from menu folder (viewer_menu.xml)
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_download"
android:title="Download" showAsAction="withText"
android:orderInCategory="2"/>
<item android:id="@+id/menu_star"
android:icon="@android:drawable/ic_menu_upload"
android:title="Star"
showAsAction="always"
android:orderInCategory="1"/>
<item android:id="@+id/menu_report"
android:title="Report Problem" showAsAction="always"
android:orderInCategory="0"/>
</menu>
It is android:showAsAction
, not just showAsAction
.
If you are using support package (android.support.v7.app.ActionBarActivity
), you have to use something like this:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_download"
android:title="Download"
app:showAsAction="withText"
android:orderInCategory="2"/>
<item android:id="@+id/menu_star"
android:icon="@android:drawable/ic_menu_upload"
android:title="Star"
app:showAsAction="always"
android:orderInCategory="1"/>
<item android:id="@+id/menu_report"
android:title="Report Problem"
app:showAsAction="always"
android:orderInCategory="0"/>
</menu>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With