自定义布局在工具栏不显示 [英] Custom layout in toolbar not showing
问题描述
我已经加入supportActionbar到我的应用程序使用V7支持库工具栏。现在,我需要出示这简直是与一些徽章车图标的动作条自定义布局。但是,当我曾经试图把,我得到的只是一个文本按钮,并没有图像显示。我的布局是:
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.
推荐答案
解决它。这是非常简单的修复。我不得不只替换的android:actionLayout =@布局/ cart_badge
与应用:actionLayout =@布局/ cart_badge
Solved it. It was very simple fix. I had to just replace android:actionLayout="@layout/cart_badge"
with app:actionLayout="@layout/cart_badge"
这篇关于自定义布局在工具栏不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!