1

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.

Vijai
  • 1,067
  • 2
  • 11
  • 25
  • Where is you toolbar? Did you create it dynamically? – denvercoder9 Mar 06 '15 at 02:49
  • I created it on a layout and included it in my Activity layout. Anyway I have solved it now. Seems like I had to put app:actionLayout instead of android. – Vijai Mar 06 '15 at 02:52

1 Answers1

3

Solved it. It was very simple fix. I had to just replace android:actionLayout="@layout/cart_badge" with app:actionLayout="@layout/cart_badge"

Vijai
  • 1,067
  • 2
  • 11
  • 25