menu option key does't appear - android
Asked Answered
D

2

0

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?

Dislocate answered 16/8, 2013 at 18:11 Comment(2)
That's up to the manufacturer. Many don't have the hard menu button anymore. Instead use the ActionBar and Overflow menu. You can't make the button show if the device doesn't have oneVerbenia
The bottom MENU button that you may be familiar with only applies to Android version 2.3.x or lower. The new menu is suppose to be in the ActionBar like a context menu. Here's more info on that: developer.android.com/guide/topics/ui/menus.htmlWinograd
S
2

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:

Overflow menu in action bar

See Say Goodbye to the Menu Button for more details.

Stace answered 16/8, 2013 at 18:16 Comment(0)
A
0

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.

Ardra answered 16/8, 2013 at 19:4 Comment(2)
This is not a good solution, doing this you say that your application will be compiled for old SDK, when there was a hardware menu button. Now the best practice is to get rid of this menu button and to put options in the action bar, as CommonsWare said.Ivatts
I agree, and I forgot to modify my answer. What I observed in the Tab, when I removed the targetSdkVersion from manifest.xml, It actually showed the menu in the Action Bar, which is at the bottom of the screen in tablets. However, the issue came in 4.x versions when I removed the line targetSdkVersion was with translate and fade-in/fade-out animations. The view was not appearing at all, which I mentioned in my question.Ardra

© 2022 - 2024 — McMap. All rights reserved.