LoginSignup
17
16

More than 5 years have passed since last update.

support-v7-appcompat を使うときの menu リソースの showAsAction

Posted at

特に、ActionBar の ActionItem として使うときのshowAsAction属性の指定の仕方にクセがあるので注意する。

通常では、showAsAction属性の名前空間はandroidなので、android:showAsActionと記述するが、support-v7-appcompat を使うときは、support-v7-appcompat 用の名前空間を使用しなければならない為、以下のようにする。

support-v7-appcompat を使いつつandroid:showAsActionとした場合は、その属性は無視され OverFlow にまとめられてしまう。

<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:compat="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_ok"
        compat:showAsAction="always"
        android:title="@string/action_ok"/> 
    <item
        android:id="@+id/action_cancel"
        compat:showAsAction="always"
        android:title="@string/action_cancel"/>
</menu>
17
16
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
17
16