如何在android 4.2中显示选项菜单

The*_*Man 5 android menuitem

我正在尝试在我的测试应用程序中创建菜单选项.

当我将清单中的主题设置为默认时,我能够看到菜单(菜单显示在顶部).如果我将清单中的主题设置为NoTitleBar.我看不到菜单选项?

我想在清单中设置主题"NoTitleBar"时获取菜单.

怎么解决?

以下是我在测试应用程序中使用的内容:

与清单:

  <uses-sdk
      android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >
    <activity
        android:name="com.ssn.menuoptions.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

menu.xml文件

 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:id="@+id/menu_preferences"
      android:title="Preferences" /> 
 </menu>
Run Code Online (Sandbox Code Playgroud)

Java文件:

@Override
public boolean onCreateOptionsMenu(Menu menu) 
    {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

有可能得到这样的东西:

文件:/// C:/Users/Koushik/Downloads/SahayaPictures/fHEQ8.png

如何让菜单显示下来?

谢谢!

Car*_*man 0

使用 notitlebar 主题会删除菜单按钮所在的操作栏。您可能必须制作一个自定义主题才能在其中包含您的菜单。如果您不采取任何措施,那么至少可以使用此属性:android:showAsAction="Never"以便使用带有菜单按钮的手机的用户可以使用其按钮弹出菜单。