简体   繁体   English

将菜单按钮添加到ActionBar选项卡

[英]Adding menu button to ActionBar Tab

I'm trying to add a menu button to the right side of the a ActionBar tab area 我正在尝试在ActionBar选项卡区域的右侧添加菜单按钮 在此处输入图片说明

Of course what I really need is a clickable Image/button that is always aligned to the right but I'm not sure how can I do it without major hacking to ActionBar or writing one my self. 当然,我真正需要的是可单击的图像/按钮,该图像/按钮始终与右侧对齐,但是我不确定如果不对 ActionBar 进行大量改动或编写自己的内容,该怎么做。 Is there a standard way to do it with ActionBar? 是否有使用ActionBar的标准方法?

Any help will be appreciated. 任何帮助将不胜感激。

UPDATE For those who suggested to use the standard way of adding a menu, this is what happens 更新对于那些建议使用添加菜单的标准方法的人,会发生这种情况

在此处输入图片说明

Thanks Yoni 谢谢Yoni

You can force the OS to put menu button in action bar but that isn't a good idea . 您可以强制 OS将菜单按钮放在操作栏中,但这不是一个好主意 Let the OS decide when to put the menu button on ActionBar. 让操作系统决定何时将菜单按钮放在ActionBar上。

Anyway I do it like this: 无论如何我是这样的:

           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) {
                Log.e("yourapp", ex.toString());
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM