No icon showing in Android Options menu item [duplicate]

一个人想着一个人 提交于 2020-01-02 03:41:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!