Show options menu button on Galaxy Nexus (Android 4.1)

后端 未结 4 1532
花落未央
花落未央 2020-12-09 13:55

I am using options menu in my app. But when I install the app on a Galaxy Nexus, I don\'t see options menu because by default it doesn\'t have options menu button. How can I

4条回答
  •  死守一世寂寞
    2020-12-09 14:36

    In Android 3.0, Google switched from having a dedicated menu key to using the ActionBar for menu functionality. If your build target is 3.0 or above, your menu will default to using the ActionBar.

    If there is a menu key on the phone, any run over options that are usually shown by the three dots icon in the action bar will instead show up with the menu button. If there is no menu key on the phone, all options will be shown on the action bar. Because the menu key is going away, it is encouraged that you utilize the ActionBar class for your menus from 3.0 and beyond.

    Now, older apps that run on new platforms without a menu key will generate a fake menu key next to the recent apps button. This makeshift menu key will only appear if your build target is 2.3.4 or below since it's only there for backwards compatibility reasons. (edit: build target should be anything less than, or including API 13)

    In your case, you should utilize the ActionBar for your menu since you're building against a newer version of Android. If you're worried about backwards compatibility then you can always utilize a library such as ActionBarSherlock to use the action bar on older platforms.

提交回复
热议问题