2016-03-21 51 views
0

我在我的应用程序中创建了一个选项菜单,出于某种原因,它在我的一部智能手机上运行,​​而不是在另一台上运行。选项菜单运行的智能手机是Android棒棒糖5.0智能手机它不工作的是软糖4.1。我不确定这是否与此有关,但我需要使用选项菜单才能在两部手机上工作。任何人对为什么会发生 我的代码休耕 MainActivity在操作栏上创建一个选项菜单

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


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_Menu) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

menu_main.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="saveourcar.soc.MainActivity"> 
    <item 
     android:id="@+id/action_Menu" 
     android:orderInCategory="100" 
     android:title="Menu" 
     app:showAsAction="never" > 
    <menu> 
     <item 
      android:id="@+id/instructions" 
      android:title="Instructions" 
      android:icon="@drawable/rench"/> 
     <item 
      android:id="@+id/hotels" 
      android:title="Hotels" 
      android:icon="@drawable/hotel"/> 

    </menu> 
    </item> 
</menu> 

enter image description hereenter image description here

+1

旧智能手机有“打开菜单”物理BUTTOM,旧的Android认识到这一点,并隐藏“3个球图标” ......试试这个添加到菜单布局:android:showAsAction =“永远” –

+0

你的爆炸。有反正我可以得到“3球”图标,虽然 –

回答

0

尝试任何想法:

在onCreateView方法:

setHasOptionsMenuEnabled(true); 

或在此菜单上的布局:

android:showAsAction="always" 
+0

第一个选项给了我一个错误,第二个没有工作。 –