Reputation: 1127
I have added supportActionbar to my app with toolBar using v7 support library. Now I need to show a custom layout on the actionbar which is simply a cart icon with a number badge. But when ever I try to put that, I get only a text button and no image is shown. My layout is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_gravity="right" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/cart_img"
android:clickable="true"
android:src="@drawable/ic_checkout"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="3dp"
android:textColor="@color/colorAccent"
android:text="0"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And I add it to the action bar using
<item
android:id="@+id/ab_cart"
android:icon="@drawable/ic_checkout"
android:actionLayout="@layout/cart_badge"
android:title="@string/action_cart"
app:showAsAction="always" />
But I only get text button "cart" in actionbar.
Upvotes: 1
Views: 991
Reputation: 1127
Solved it. It was very simple fix. I had to just replace android:actionLayout="@layout/cart_badge"
with app:actionLayout="@layout/cart_badge"
Upvotes: 3