如何在平板电脑打开OptionsMenu? [英] How to open OptionsMenu on tablet?

查看:120
本文介绍了如何在平板电脑打开OptionsMenu?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一款Android应用,主要针对智能手机。然而,在平板电脑模拟器我看到它适用于Android 3.X了。

I have developed an android app that mainly targets smartphones. However in tablet emulator I see that it works on android 3.x, too.

然而,有一个小问题。当他点击菜单按钮,用户无法打开OptionsMenu。正如你所知道的智能手机显示一个菜单从底部。但在平板电脑没有任何反应。

However there is one little problem. The user cannot open OptionsMenu when he clicks on the menu button. As you know on the smartphone a menu appears from the bottom. But on tablet nothing happens.

我已阅读本 http://developer.android。 COM /引导/主题/ UI / menus.html#选项菜单但仍无法弄清楚如何管理这一点。我的应用程序有一个自定义操作栏。

I have read this http://developer.android.com/guide/topics/ui/menus.html#options-menu but still cannot figure out how to manage this. My app has a custom action bar.

我的code是相当直截了当。在主要活动:

My code is quite straight forward. In main activity:

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    //...
    }
}

而preFS活动:

And the prefs activity:

public class MdPrefsActivity extends PreferenceActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         getPreferenceManager().setSharedPreferencesName(
                 MdSharedPrefs.PREFS_NAME);
         addPreferencesFromResource(R.xml.prefs);
     }
}

MdShared preFS类只包含一些getter和setter方法​​来检索/写preF值。

MdSharedPrefs class just contains some getters and setters to retrieve/write the pref values.

任何想法我怎么能显示在平板电脑OptionsMenu?

Any ideas how I can show the OptionsMenu on tablet?

推荐答案

作为文档说:

在选项菜单项是两种不同的方式访问:在
  MENU按钮,或在操作栏(​​在运行Android 3.0或设备
  更高)。

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).

[...]

在Android 3.0及更高版本,从选项菜单项被放置在
  操作栏,这在活动的顶部出现在的地方
  传统的标题栏。默认情况下,从选项菜单中的所有项目
  放置在溢流菜单,其中用户可以通过触摸开
  操作栏右侧的菜单图标。但是,你可以
  直接将选择菜单项中的操作栏为行动项目
  即时访问[...]

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

因此​​,对于的Andr​​oid 3.0或更高版本您可以看到的菜单项动作条

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

同样重要的是要注意的是:

It is also important to notice that:

采用Android 3.0(API级别11)开始,包括在操作栏
  在使用该Theme.Holo主题(或者一个所有活动的
  后代),这是默认的主题时,无论是
  targetSdkVersion或的minSdkVersion属性被设置为11或更大。

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"

这篇关于如何在平板电脑打开OptionsMenu?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆