2015-10-01 88 views
0
<item 
     android:id="@+id/members" 
     android:orderInCategory="100" 
     android:title="@string/members" 
     app:showAsAction="never" /> 


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





@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      // Respond to the action bar's Up/Home button 

      case R.id.members: 
       Intent intent = new Intent(this, GroupDetailActivity.class); 
       intent.putExtra("name", toolbarText); 
       intent.putExtra("groupId", currentGroupId); 
       startActivity(intent); 
       break; 

      case android.R.id.home: 
       finish(); 

       } 
       return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

我有工具欄包含一個家,一個項目成員的代碼工作正常,但一個活動,如果我點擊菜單項成員是顯示在設備上的硬件菜單按鈕該裝置的底部,而不是錨工具欄硬件菜單點擊從底部popuping不是從工具欄

+0

閱讀本http://stackoverflow.com/questions/9286822/how-to-force-use溢出菜單上的設備與菜單按鈕和這個http://developer.android.com/design/patterns/c ompatibility.html – Emil

+0

@vaisakh是我的答案,下面的工作? –

回答

1

添加以下代碼片段在onCreate方法,

ActionBar actionBar = getActionBar(); 
     actionBar.setHomeButtonEnabled(true); 
     actionBar.setDisplayHomeAsUpEnabled(true); 
     try { 
       ViewConfiguration config = ViewConfiguration.get(this); 
       Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); 
       if(menuKeyField != null) { 
        menuKeyField.setAccessible(true); 
        menuKeyField.setBoolean(config, false); 
       } 
      } catch (Exception ex) { 
       // Ignore 
      } 
相關問題