有没有办法强制三星Galaxy S3在屏幕右上角固定选项菜单的位置,就像其他流行手机一样?在三星Galaxy S3中,选项菜单仅在菜单按钮下方可用。我希望在所有类型的设备上将内置帮助放置在固定位置。
我不确定其他类型的手机/平板电脑是否存在类似的问题。
有没有办法强制三星Galaxy S3在屏幕右上角固定选项菜单的位置,就像其他流行手机一样?在三星Galaxy S3中,选项菜单仅在菜单按钮下方可用。我希望在所有类型的设备上将内置帮助放置在固定位置。
我不确定其他类型的手机/平板电脑是否存在类似的问题。
在包含选项菜单的活动中,使用以下代码块:
try {
ViewConfiguration config = ViewConfiguration.get(BaseActivity.this);
Field menuKeyField = ViewConfiguration.class
.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
通过此代码块,您可以从操作栏的右上角访问选项菜单。
即使在三星Galaxy S3上,当您点击菜单按钮时,选项菜单也将从操作栏的右上角打开。
请尝试使用以下menu.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:orderInCategory="2"
android:title="Home"/>
<item
android:id="@+id/logs"
android:orderInCategory="3"
android:title="Logs"/>
<item
android:id="@+id/support"
android:orderInCategory="4"
android:title="Support"/>
<item
android:id="@+id/logout"
android:orderInCategory="5"
android:title="Logout"/>
</menu>
你可以在你的活动中尝试这个:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_whatever:
// do your thing here
return true;
}
return super.onOptionsItemSelected(item);
}
在 /res/menu/main.xml 中
<item android:id="@+id/action_whatever"
android:title="@string/action_text"
android:orderInCategory="100"
android:icon="@drawable/ic_overflow"
android:showAsAction="always" />