Android自定义菜单图标无法显示

时间:2016-04-28 21:49:44

标签: android menu icons menuitem

我无法使用自定义图标而非标准3点菜单图标。这就是我所拥有的:

menu_editor.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemes.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.sunnyvalleystudio.notetakingapp.EditorActivity"
    >
    <item
        android:id="@+id/action_delete"
        android:icon="@drawable/ic_action_delete"
        android:title="@string/action_delete"
        android:orderInCategory="100"
        app:showAsAction="always"
        />
    <!--to show it in menu we need to change "never" to "always -->
</menu>

EditorActivity.java

 @Override
    public boolean onCreateOptionsMenu(Menu menu){
        //inflate the menus - adds items to the action bar menu if it is present
        //MenuInflater gets the menu items from an existing XML file

        //to display delete icon only in the existing notes
        if (action.equals(Intent.ACTION_EDIT)){
            MenuInflater inflater =  getMenuInflater();
            inflater.inflate(R.menu.menu_editor, menu);

        }
        return true;
    }

尽管如此,我仍然会在其列表中获得带有“删除”位置的3点图标。为什么不显示ic_action_delete图标?它在资产中。我正在使用Nexus 5 API 19仿真器。

1 个答案:

答案 0 :(得分:0)

尝试在inflate()方法中添加你的包名(com.sunnyvalleystudio.notetakingapp。),然后返回super.onCreateOptionsMenu(menu);