How to open OptionsMenu on tablet?

◇◆丶佛笑我妖孽 提交于 2019-12-06 02:13:58

As the documentation said:

Items in the Options Menu are accessible in two distinct ways: the MENU button or in the Action Bar (on devices running Android 3.0 or higher).

[...]

On Android 3.0 and higher, items from the Options Menu is placed in the Action Bar, which appears at the top of the activity in place of the traditional title bar. By default all items from the Options Menu are placed in the overflow menu, which the user can open by touching the menu icon on the right side of the Action Bar. However, you can place select menu items directly in the Action Bar as "action items," for instant access [...]

So for Android 3.0 or higher you can see only the menu items in the ActionBar.

It is also important to notice that:

Beginning with Android 3.0 (API level 11), the action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or greater.

But be aware that the ActionBar is visible only if you don't have an application or activity theme that explicitly hides it like

android:theme="@android:style/Theme.Holo.NoActionBar"

On a tablet, no hardware button that can be used to load the menus, you need to create two folders in your res: the first call it values-11 and the second call it values-14. Inside these folders, put these styles (styles.xml) that will replace your default basetheme in the values folder whenever devices of higher version are used:

Res/values-11

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

Res/values-14

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>

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