三星Galaxy S3中的选项菜单

3

有没有办法强制三星Galaxy S3在屏幕右上角固定选项菜单的位置,就像其他流行手机一样?在三星Galaxy S3中,选项菜单仅在菜单按钮下方可用。我希望在所有类型的设备上将内置帮助放置在固定位置。

我不确定其他类型的手机/平板电脑是否存在类似的问题。


创建您自己的自定义选项菜单,无论您想要放置在哪里,只需设置并使用它。 - Pratik Dasa
你想强制显示选项菜单作为溢出菜单(带有三个点的图标)吗? - Pravin
是的,我需要在屏幕右上角有三个点的图标。 - Annabelle
@Annabelle 那么就放一张带3个点的图片,点击它时打开一个附着在3个点上的PopupWindow,就这样。 - Pratik Dasa
@Annabelle,请检查我的答案... - Pravin
2个回答

7

在包含选项菜单的活动中,使用以下代码块:

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>

完美!这就是我在寻找的 :) - Annabelle
1
这就是“最佳”解决方案! - Seraphim's

0

你可以在你的活动中尝试这个:

 @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" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接