果冻豆中的操作栏不显示选项菜单

action bar not showing options menu in jelly bean

操作栏在果冻豆中不显示选项菜单,而在棒棒糖中显示。 这是我的 styles.xml`

 <resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#00796B</item>
    <item name="colorPrimaryDark">#004D40</item>
    <item name="colorAccent">#c51162</item>
   <item name="android:textColorPrimary">@color/abc_primary_text_disable_only_material_dark</item>


</style>


 </resources>` 

这是我的应用程序gradle

 compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.example.dell.syncytium"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
   }

我的 MainActivity 扩展了 AppCompatActivity。 请提前帮助me.thanks

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    menu.add(0, logoutMenu, 0, "Logout");
    menu.add(0,Play,1,"Play Music");
    menu.add(0,Stop,2,"Stop Music");
    return result;
  }

menu.xml

<menu 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools" 
 tools:context=".MainActivity">
<item
    android:id="@+id/connect_scan"
    android:icon="@drawable/menu"
    android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/discoverable"
    android:icon="@android:drawable/ic_menu_mylocation"
    android:showAsAction="ifRoom|withText"/>
</menu>

MainActivity.java

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.menu:
         break;
        case R.id.discoverable:
         break;
    }
    return false;
  }
}

You can make menu from your activity itself without menu.xml file but it will provide you single option on action bar.....

试试这个..

 public class MainActivity extends Activity {


 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // ---- //

 }
 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 1, 1, "New");
        menu.add(0, 2, 2, "Create");
        menu.add(0, 3, 3, "Open");
        menu.add(0, 4, 4, "Delete");
        menu.add(0, 5, 5, "Exit");

        return true;
    }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case (1):
           //----//
            return true;
        case (2):
           //---//
            return true;
        case (3):
           //---//
            return true;
        case (4):
            //---//
            return true;
        case (5):
            finish();
            return true;

        }
        return false;
    }
 }

输出