不显示Android的操作栏三个点 [英] Android Action Bar Three Dots not displayed

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

问题描述

请帮忙, 我做了一个自定义菜单(添加支持库)(名称 - > main_activity_actions.xml)

 < XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:yourapp =htt​​p://schemas.android.com/apk/res-auto>

<项目
    机器人:ID =@ ID /搜索
    机器人:图标=@可绘制/搜索
    机器人:标题=@字符串/搜索
    yourapp:showAsAction =ifRoom/>
<项目
    机器人:ID =@ ID / view_all
    机器人:标题=@字符串/ view_all
    yourapp:showAsAction =从不/>
<项目
    机器人:ID =@ + ID / action_settings
    yourapp:showAsAction =从不
    机器人:标题=@字符串/ action_settings/>
 

现在我应该怎么做才能把action_settings到三个点(的操作栏),而不是硬件菜单按钮(无任何黑客)。

MainActivity

  @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.main_activity_actions,菜单);
    返回true;
}
 

嗯,我已经找到了破解,但如果有任何其他方式然后让我知道,
哈克
把这个code中的onCreate

 尝试{
        ViewConfiguration配置= ViewConfiguration.get(本);
        现场menuKeyField = ViewConfiguration.class.getDeclaredField(sHasPermanentMenuKey);
        如果(menu​​KeyField!= NULL){
            menuKeyField.setAccessible(真正的);
            menuKeyField.setBoolean(配置,FALSE);
        }
    }赶上(例外前){
        // 忽略
    }
 

有关这一点,你需要导入

 进口java.lang.reflect.Field中;
进口android.view.ViewConfiguration;
 

解决方案

无任何黑客,你不能这样做,在所有设备上。具有硬件菜单按钮,这些设备(我不知道是否绝对全部)将使用溢出按钮(...),它代替。

其中,排序,是一件好事。这些设备的用户习惯于pressing菜单按钮回到菜单。因此对他们来说,缺乏溢流按钮是正常行为。

对于那些使用溢出按钮设备,Android将决定自己在哪里有什么根据在 showAsAction 标签的提示放。它取决于屏幕尺寸,方向,除其他事项。 此页面显示有多少图标显示的表格(一部分划入溢出菜单)。

Please help, I made a custom menu (added support libraries) (name-> main_activity_actions.xml)

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto"  >

<item
    android:id="@id/search"
    android:icon="@drawable/search"
    android:title="@string/search"
    yourapp:showAsAction="ifRoom" />
<item
    android:id="@id/view_all"
    android:title="@string/view_all"
    yourapp:showAsAction="never"/>
<item
    android:id="@+id/action_settings"
    yourapp:showAsAction="never"
    android:title="@string/action_settings"/>

Now what should i do to put action_settings into three dots (of action bar), instead of hardware menu button (Without any hack).

MainActivity

@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_activity_actions, menu);
    return true;
}

well i have found the hack but if there is any other way then let me know,
Hack
put this code in 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 ex) {
        // Ignore
    }

for this you need to import

import java.lang.reflect.Field;
import android.view.ViewConfiguration;

解决方案

Without any hack, you cannot do that on all devices. Those devices that have the hardware menu button (I'm not sure if absolutely all) will use it instead of the overflow button (...).

Which, sort of, is a good thing. Users of those devices are used to pressing the menu button to get to the menu. So for them, the lack of the overflow button is the normal behaviour.

For those devices that use the overflow button, Android will decide itself what to put where based on your hints in showAsAction tag. It depends on the screen size, orientation, among other things. This page has a table showing how many icons are displayed (the rest goes to overflow menu).

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

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