我在我的应用程序,我已经测试工作在Android 4.0的一个选项菜单。 在code为如下图所示:
I have a options menu in my application which I have tested to work on Android 4.0. The code is as shown below:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
/**
* Event Handling for Individual menu item selected
* Identify single menu item by it's id
* */
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_share:
//code to do something when chosen etc
return true;
default:
return super.onOptionsItemSelected(item);
}
}
现在,如果我运行在Android 4.4在同一code(我测试了摩托G),选项菜单没有出现。
Now if I run the same code on Android 4.4 (I tested on Moto G), the options menu is not appearing.
知不知道我必须做的,因为有关联的设备?
Any idea what I must do since there is no Android menu button on the device?
您的活动类里面将这个如果要强制应用程序以显示操作溢出:
Put this inside your activity class if you want to Force to the Application to show the Action Overflow:
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
}