2017-03-20 27 views
0

我正在用模擬器測試我的應用程序,我的3點按鈕顯示完美。3點按鈕出現在仿真器中,但不在devie中

當我使用我的真實設備(Samsung Galaxy S3)進行測試時,那些3點按鈕從未出現過,我不知道爲什麼。相反,我得到的所有3個按鍵,而我只想要1個+ 3個按鈕...

這裏是我的菜單

這裏的OnCreate中和的SelectedItem方法

@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_affichage_notes,menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) 
    { 
     case R.id.action_logout: 
      //création d'un Intent 
      Intent intent = new Intent(AffichageNotes.this, PageAccueil.class); 
      //ajout de fonctionnalités qui vont être transférés 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | 
        Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
      //transfert aussi de la valeur EXIT qui est true 
      intent.putExtra("EXIT", true); 
      startActivity(intent); 
      return true; 
     case R.id.action_setting: 
      Intent a = new Intent(AffichageNotes.this,Reglages.class); 
      startActivity(a); 
      return true; 
     case R.id.action_add: 
      Intent i = new Intent(AffichageNotes.this,AjoutTexte.class); 
      Bundle args = new Bundle(); 
      int id = getIntent().getIntExtra("id",0); 
      i.putExtra("id",id); 
      startActivity(i); 
      return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

錯誤來自哪裏?感謝你們 !

回答

0

你把你的物品放在菜單裏面嗎?

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item 
    android:id="@+id/action_add" 
    android:icon="@drawable/ic_action_add" 
    android:title="Ajouter Cours" 
    app:showAsAction="always" /> 

    <item 
     android:id="@+id/action_setting" 
     android:title="Réglages" 
     android:icon="@drawable/ic_action_setting" 
     app:showAsAction="never" 
     /> 
    <item 

     android:id="@+id/action_logout" 
     android:title="Se déconnecter" 
     android:icon="@drawable/ic_action_logout" 
     app:showAsAction="never" 
     /> 

</menu> 

編輯:使解決方案可見

try { 
     ViewConfiguration config = ViewConfiguration.get(this); 
     FieldmenuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuK‌​ey"); 
     if (menuKeyField != null) { 

     menuKeyField.setAccessible(true); 
     menuKeyField.setBoolean(config, false); 
     } 
    } catch (Exception ex) { 
     return; 
    } 
+0

哦,是的,是的,我板缺並沒有注意到它抱歉.. – David

+0

@大衛,你能看到動作欄?也許你因爲你的主題看不到,你可以發佈你的style.xml文件嗎? –

+1

找到解決方案! '嘗試ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField(「sHasPermanentMenuKey」); (menuKeyField!= null){ menuKeyField.setAccessible(true); menuKeyField.setBoolean(config,false); (例外){ //忽略 } – David

相關問題