无法显示图标选项菜单(Cannot Display Icon In The Options Menu

2019-08-31 08:09发布

你好,大家好我真的很沮丧,这是我想要得到

但我什么都这样,我不能让我的图标键合到我的选项菜单。 我试过了

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    menu.add(1, 1, 0, "Blu-Ray").setIcon(R.drawable.ic_launcher);
     menu.add(1, 2, 1, "DVD").setIcon(R.drawable.ic_launcher);
     menu.add(1, 3, 2, "Hard Disk").setIcon(R.drawable.ic_launcher);
     menu.add(1, 4, 3, "Sites").setIcon(R.drawable.ic_launcher);
     menu.add(1, 5, 4, "USB").setIcon(R.drawable.ic_launcher);
 return true;
}

但没有运气

然后,我尝试去我的菜单,然后main.xml中,做了

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_settings"
    android:icon="@drawable/ic_launcher"
    android:showAsAction="never"
    android:title="Lolly"/>

而在我的班级我做

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

Answer 1:

Cannot Display Icon In The Options Menu

Note that there is no more "options menu" as of Android 3.0. There is the action bar overflow. "Options menu" is still used in some method names (e.g., onCreateOptionsMenu()) for backwards compatibility, but the "options menu" itself is an Android 1.x/2.x construct.

Hello guys I am really frustrated this is what I want to get

That is not an options menu, nor the action bar overflow. It is some UI that the developer of that app created independently.

but I what ever I do I cannot get my icon bonded to my Options Menu

The action bar overflow does not have icons. The old options menu had icons, but with a different rendering than is depicted in your screenshot.

I would like to achieve the layout as above

You are welcome to create some UI for this yourself. Or, you can stick to the standard action bar/options menu approach, so that your application will behave consistently with the other applications on the users' devices.



文章来源: Cannot Display Icon In The Options Menu