Android的操作栏不显示溢出 [英] Android action bar not showing overflow

查看:114
本文介绍了Android的操作栏不显示溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的操作栏有3项。

I have an action bar in my app with 3 items.

只有2可能会由于空间问题显示出来,所以我希望首先被显示,剩下的将被显示在溢出。 然而,在实践中,只有第2项被示出和没有溢出检测

Only 2 can be displayed due to space issues, so I'd expect the first to be displayed and the rest to be displayed in the overflow. However in practice only the first 2 items are shown and there is no overflow detectable.

下面是相关code: list_menu.xml

Here is the relevant code: list_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_insert"
    android:icon="@android:drawable/ic_menu_add"
    android:title="@string/menu_insert" 
    android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_call"
    android:icon="@android:drawable/ic_menu_call"
    android:title="@string/menu_call" 
    android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_agenda"
    android:icon="@android:drawable/ic_menu_agenda"
    android:title="@string/menu_agenda" 
    android:showAsAction="ifRoom|withText"/>
</menu>

Activity.java

Activity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater mi = getMenuInflater();
    mi.inflate(R.menu.list_menu, menu);
    return true;
}

谢谢!

推荐答案

如果你想显示的三个点,而不管设备菜单按钮!那么您可以在您的应用程序类的调用此方法onCreate方法 -

If you want to show the three dots, irrespective of device menu button! then you can call this method in your application class' onCreate method-

private void makeActionOverflowMenuShown() {
    //devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
    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) {
        Log.d(TAG, e.getLocalizedMessage());
    }
}

这篇关于Android的操作栏不显示溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆