Android Actionar overflow 不显示的问题

来源:互联网 发布:adams测量结果数据导出 编辑:程序博客网 时间:2024/06/06 05:45

在此直接引用网上的一篇文章 : 

Android action bar not showing overflow


总结一下为什么overflow 不显示的原因就是因为你的设备有实体的menu 键(自从4.4以后好像很多手机原来的实体menu键不再是menu的功能了,所以不存在这问题),所以如果要想显示overflow 有几种方式

·1: 通过反射 在Activity 的OnCreate 中调用,其目的是让"sHasParmanenMenuKey" = false。不过好像在 Android action bar not showing overflow 文章中有人说道在某个平台版本上无效,而且这篇文章不建议使用这种方法,起原因是 “This is an awful hack that breaks consistency with the rest of the apps on the platform. Do not do this”就是说这样破坏了其他应用在这个平台使用的一致性,其实对中国来说貌似有没什么公司或者个人会遵循google的设计,都是抄,再抄,所以也无所谓。

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());    }}
· 第二种 :

<item    android:id="@+id/a_More"    android:icon="@drawable/more"    android:showAsAction="always"    android:title="More">    <menu>        <item            android:id="@+id/aM_Home"            android:icon="@drawable/home"            android:title="Home"/>    </menu></item>

0 0
原创粉丝点击