定义操作栏溢出项 [英] define Action bar overflow items

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

问题描述

如果我为操作栏定义了以下项目:

res/menu/action_menu.xml:

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

    <item android:title="label"/>
    <item android:title="label1"/>
    <item android:title="label2"/>
    <item android:title="label3"/>
    <item android:title="label4"/>

</menu>

在我的活动中:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.action_menu, menu);
    return true;
}

是否仍然可以让我定义某些项目移至动作溢出部分?以及如何做?

P.S. 动作溢出部分是动作栏的最右侧部分,用于隐藏某些项目,如弹出菜单.

解决方案

反之亦然.您需要通过设置适当的标志来明确告诉菜单ActionBar中需要哪些菜单,而不必通过设置相应的标志

例如

<item android:id="@+id/refresh"
      android:title="@string/refresh"
      android:icon="@drawable/reload_button"
      android:showAsAction="always"/>

此处android:showAsAction讲述了如何处理它.选项是

  • 总是
  • ifRoom
  • 从不
  • withText

您可以将管道符号或选项与管道符号一起设置为"always | withText"

有关更多文档,请参见android 文档以获取操作栏./p>

If I define the following items for my action bar:

res/menu/action_menu.xml :

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

    <item android:title="label"/>
    <item android:title="label1"/>
    <item android:title="label2"/>
    <item android:title="label3"/>
    <item android:title="label4"/>

</menu>

In my Activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.action_menu, menu);
    return true;
}

Is there anyway to allow me define certain items move to action overflow part ? and how to do it?

P.S. Action overflow part is the right-most part of action bar which hide certain items like a popup menu.

解决方案

It's the other way round. You need to explicitly tell the menu which ones you want in the ActionBar and which not by setting the appropriate flags

E.g.

<item android:id="@+id/refresh"
      android:title="@string/refresh"
      android:icon="@drawable/reload_button"
      android:showAsAction="always"/>

Here android:showAsAction tells how to handle it. Options are

  • always
  • ifRoom
  • never
  • withText

You can or options together with the pipe symbol as "always|withText"

See the android docs for action bar for more documentation.

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

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