工具栏中的自定义布局未显示

时间:2015-03-06 02:46:01

标签: android android-layout android-actionbar android-toolbar

我已使用v7支持库将supportActionbar添加到我的应用程序中。现在我需要在操作栏上显示自定义布局,这只是一个带有数字徽章的购物车图标。但是,当我试图把它放在那里时,我只得到一个文本按钮,没有显示图像。我的布局是:

<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>

然后我使用

将其添加到操作栏
<item
android:id="@+id/ab_cart"
android:icon="@drawable/ic_checkout"
android:actionLayout="@layout/cart_badge"
android:title="@string/action_cart"
app:showAsAction="always" />

但我只在动作栏中输入文字按钮“cart”。

1 个答案:

答案 0 :(得分:2)

解决了它。这是非常简单的修复。我不得不用android:actionLayout="@layout/cart_badge"

替换app:actionLayout="@layout/cart_badge"