android-如何在平板电脑上打开OptionsMenu?

android-如何在平板电脑上打开OptionsMenu?,第1张

概述我开发了一个主要针对智能手机的android应用.但是,在平板电脑模拟器中,我看到它也可以在android3.x上运行.但是,有一个小问题.用户单击菜单按钮时无法打开OptionsMenu.如您所知,在智能手机上,菜单从底部出现.但是在平板电脑上什么也没发生.我已经阅读了http://developer.android

我开发了一个主要针对智能手机的android应用.但是,在平板电脑模拟器中,我看到它也可以在androID 3.x上运行.

但是,有一个小问题.用户单击菜单按钮时无法打开OptionsMenu.如您所知,在智能手机上,菜单从底部出现.但是在平板电脑上什么也没发生.

我已经阅读了http://developer.android.com/guide/topics/ui/menus.html#options-menu,但仍然无法弄清楚如何进行管理.我的应用程序有一个自定义 *** 作栏.

我的代码很简单.在主要活动中:

@OverrIDepublic boolean onCreateOptionsMenu(Menu men) {    MenuInflater inflater = getMenuInflater();    inflater.inflate(R.layout.menu, men);    return true;}@OverrIDepublic boolean onoptionsItemSelected(MenuItem item) {    // Handle item selection    switch (item.getItemID()) {    //...    }}

和prefs活动:

public class MdPrefsActivity extends PreferenceActivity {     @OverrIDe     protected voID onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         getPreferenceManager().setSharedPreferencesname(                 mdsharedPrefs.PREFS_name);         addPreferencesFromresource(R.xml.prefs);     }}

mdsharedPrefs类仅包含一些getter和setter来检索/写入pref值.

有什么想法可以在平板电脑上显示OptionsMenu吗?

解决方法:

如文档所述:

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 […]

因此,对于AndroID 3.0或更高版本,您只能在Actionbar中看到菜单项.

注意以下几点也很重要:

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.

但是请注意,只有在没有显式隐藏它的应用程序或活动主题时,才可以看到Actionbar

androID:theme="@androID:style/theme.Holo.NoActionbar"
总结

以上是内存溢出为你收集整理的android-如何在平板电脑上打开OptionsMenu?全部内容,希望文章能够帮你解决android-如何在平板电脑上打开OptionsMenu?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1085065.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存