<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);
}
我有一个包含主页和项目成员的工具,代码工作正常但是如果我点击设备上的硬件菜单按钮,菜单项成员显示在设备的底部而不是工具栏的锚点
答案 0 :(得分: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
}