模拟器显示菜单项。
在平板电脑上运行.apk需要显示它。
设备:Samsung Android 4.1
Code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.options, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent(StockInfo.this,chart.class);
intent.putExtra("companycode", companyCode);
Log.e("code", companyCode);
startActivity(intent);
return super.onOptionsItemSelected(item);
}
答案 0 :(得分:0)
如果您的设备有硬件菜单按钮,菜单项将不会显示,您可以通过在oncreate中添加以下代码来破解它。在平板电脑中它将显示菜单项,因为平板电脑包含菜单硬件按钮
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}