I have exactly the same problem as in these threads:
No actions or icons showing on the actionbar; only in overflow
Menu items won't show up in the actiobar
No one has offered a solution, so I want to bring it up again.
I have a xml-file, my_menu.xml, that look like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/delete"
android:showAsAction="ifRoom|withText"
android:icon="@drawable/ic_delete_image"
android:title="delete"/>
</menu>
My activity extends ActionBarActivity and implements these methods:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.delete:
//delete something
break;
}
return(true);
}
In my book: "A value of ifRoom means that the menu item will appear in the action bar if there is space for it" - I have tested to use ifRoom, ifRoom|withText and always, but the item always ends up in the overflow menu. I have tested the application on different devices, and it's plenty of room. Do anyone have a solution to this?
Hank
My activity extends ActionBarActivity
As is covered in the documentation , if you are using the appcompat_v7
backport of the action bar, and its associated ActionBarActivity
, your menu resource needs to have showAsAction
in a namespace custom to your app:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/delete"
yourapp:showAsAction="ifRoom|withText"
android:icon="@drawable/ic_delete_image"
android:title="delete"/>
</menu>
Here is a complete sample project demonstrating the use of the appcompat_v7
action bar.
Try changing it to
<item
android:id="@+id/delete"
android:showAsAction="always|withText"
android:icon="@drawable/ic_delete_image"
android:title="delete"/>
Hope this will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.