Custom layout in toolbar not showing

依然范特西╮ 提交于 2019-12-11 11:16:35

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/28891582/custom-layout-in-toolbar-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!