2016-03-21 49 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

第一個選項給了我一個錯誤,第二個沒有工作。 –