I just wanted to point out this really handy method that lets you specify your own layout for an action item.
<strong>android:actionlayout=”@layout/action_layout”</strong>
Super cool albeit a bit obscure!
This is all you need to do:
In your menu xml:
<item android:id="@+id/menu_item" android:showAsAction="always|withText" android:actionLayout="@layout/action_layout" android:title="@string/menu_settings"/>
It’s that simple!
Your layout can be anything! in my case i just tried it out with a button.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".CacheTestActivity" > <ImageButton android:layout_width="wrap_content" android:layout_height="match_parent" android:contentDescription="Custom button!" android:scaleType="fitCenter" android:src="@drawable/logo" /> </LinearLayout>
This really makes it simple to customize your actionbar action items!
Hope this helps!
2 comments on “How to customize actionbar items”