LoginSignup
12
8

More than 5 years have passed since last update.

Menu resource の item の showAsAction

Posted at

actionBar のオプションメニューの項目を常に表示しようと思ったときに調べたことのメモ。

<menu> の書式が以下の通り。
その中でも app:showAsAction についての日本語訳(Google翻訳) を以下掲載。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@[+][package:]id/resource_name"
          android:title="string"
          android:titleCondensed="string"
          android:icon="@[package:]drawable/drawable_resource_name"
          android:onClick="method name"
          android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]
          android:actionLayout="@[package:]layout/layout_resource_name"
          android:actionViewClass="class name"
          android:actionProviderClass="class name"
          android:alphabeticShortcut="string"
          android:alphabeticModifiers=["META" | "CTRL" | "ALT" | "SHIFT" | "SYM" | "FUNCTION"]
          android:numericShortcut="string"
          android:numericModifiers=["META" | "CTRL" | "ALT" | "SHIFT" | "SYM" | "FUNCTION"]
          android:checkable=["true" | "false"]
          android:visible=["true" | "false"]
          android:enabled=["true" | "false"]
          android:menuCategory=["container" | "system" | "secondary" | "alternative"]
          android:orderInCategory="integer" />
    <group android:id="@[+][package:]id/resource name"
           android:checkableBehavior=["none" | "all" | "single"]
           android:visible=["true" | "false"]
           android:enabled=["true" | "false"]
           android:menuCategory=["container" | "system" | "secondary" | "alternative"]
           android:orderInCategory="integer" >
        <item />
    </group>
    <item >
        <menu>
          <item />
        </menu>
    </item>
</menu>

android:showAsAction

この項目がアプリケーションバーにアクション項目として表示されるタイミングと方法を指定する属性
アクティビティにアプリバーが含まれている場合にのみ、メニュー項目をアクション項目として表示できます。
以下が有効な値。

Keyword. When and how this item should appear as an action item in the app bar. A menu item can appear as an action item only when the activity includes an app bar. Valid values:

ifRoom

空きがある場合にのみ、このアイテムをアプリバーに配置してください。
「ifRoom」とマークされたすべてのアイテムのためのスペースがない場合、最も低いorderInCategory値を持つアイテムがアクションとして表示され、残りのアイテムはオーバーフローメニューに表示されます。

Only place this item in the app bar if there is room for it. If there is not room for all the items marked "ifRoom", the items with the lowest orderInCategory values are displayed as actions, and the remaining items are displayed in the overflow menu.

withText

アクション項目にタイトルテキスト(android:titleで定義)も含めます。
パイプで区切ることで、この値を他のフラグとともにフラグセットとして含めることができます。

Also include the title text (defined by android:title) with the action item. You can include this value along with one of the others as a flag set, by separating them with a pipe

never

このアイテムをアプリバーに配置しないでください。
代わりに、アプリバーのオーバーフローメニューに項目をリストしてください。

Never place this item in the app bar. Instead, list the item in the app bar's overflow menu.

always

常にこのアイテムをアプリバーに配置してください。
項目が常にアクションバーに表示されることが重要でない限り、これを使用しないでください。
複数の項目を常にアクション項目として表示するように設定すると、それらがアプリケーションバーの他のUIと重なることがあります。

Always place this item in the app bar. Avoid using this unless it's critical that the item always appear in the action bar. Setting multiple items to always appear as action items can result in them overlapping with other UI in the app bar.

collapseActionView

このアクション項目に関連付けられているアクションビュー(android:actionLayout またはandroid:actionViewClassで宣言されているとおり)は折りたたみ可能です。
APIレベル14で導入されました。

The action view associated with this action item (as declared by android:actionLayout or android:actionViewClass) is collapsible.
Introduced in API Level 14.


詳細については、App Barを追加するトレーニングクラス を参照してください。
APIレベル11で導入されました。

See the Adding the App Bar training class for more information.
Introduced in API Level 11.

原文

Menu resource | Android Developers

12
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
8