问题
I have created an options menu with an icon I made myself (24px x 24px) but it is not showing.
The code in my xml (located in res/menu) is the following:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_insert"
android:icon="@drawable/menu_add"
android:title="@string/menu_insert" />
</menu>
The menu is created in my Activity.java file as said in the documentation:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.list_menu, menu);
return true;
}
PS The item's title is located all the way to the left and I can't seem to find anywhere in the documentation how to center it (apparently android:gravity is not done there)
Thanks
回答1:
I think your call to super.onCreateOptionsMenu(menu)
should be deleted, it's not necessary and seems to alter your menu.
来源:https://stackoverflow.com/questions/9730298/no-icon-showing-in-android-options-menu-item