menu option key does't appear - android

帅比萌擦擦* 提交于 2019-12-13 04:37:25

问题


I am beginner , i wrote these codes for option menu , but in new Phones like Nexus4 menu option key does not appear (it should appear near back key on bottom of screen).

my codes :

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

and

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu1:
        menu1_action();
        return false;
    default:
        return super.onOptionsItemSelected(item);
    }
}

and

<?xml version="1.0" encoding="utf-8"?>

<item
    android:id="@+id/menu1"
    android:icon="@drawable/menu1
    android:showAsAction="ifRoom"
    android:title="@string/menu1"/>

what's the problem?


回答1:


but in new Phones like Nexus4 menu option key does not appear (it should appear near back key on bottom of screen)

Ideally, it will not. Ideally, it will be a "..." button in the action bar, for devices like the Nexus 4 that lack an off-screen MENU button:

See Say Goodbye to the Menu Button for more details.




回答2:


Well, I had the same problem recently in Android 4.x versions. I don't really know what the issue is but try to put below line in your manifest.xml file.

android:targetSdkVersion="17";

Let me know if it did the trick for you. It did for me in Samsung Tab 2.

EDIT:

I am sorry. I reconfirmed by testing on device and the Menu for me appeared on the Action Bar when I actually removed targetSdkVersion from my manifest.xml file, otherwise it was being displayed on the Title Bar, where we see the name of the application. But as I needed to use the theme without title-bar, I removed targetSdkVersion from manifest.xml.



来源:https://stackoverflow.com/questions/18279637/menu-option-key-doest-appear-android

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