gpt4 book ai didi

android - 如何在平板电脑上打开选项菜单?

转载 作者:太空宇宙 更新时间:2023-11-03 13:34:38 26 4
gpt4 key购买 nike

我开发了一款主要针对智能手机的安卓应用。但是在平板电脑模拟器中我看到它也适用于 android 3.x。

不过有个小问题。用户在单击菜单按钮时无法打开 OptionsMenu。如您所知,在智能手机上会从底部出现一个菜单。但在平板电脑上没有任何反应。

我读过这个http://developer.android.com/guide/topics/ui/menus.html#options-menu但仍然无法弄清楚如何管理它。我的应用程序有一个自定义操作栏。

我的代码非常简单。在主要 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()) {
//...
}
}

以及首选项 Activity :

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 只有在您没有像

这样显式隐藏它的应用程序或 Activity 主题时才可见
android:theme="@android:style/Theme.Holo.NoActionBar"

关于android - 如何在平板电脑上打开选项菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8841877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com