在一个按钮中添加多个图像和文本

时间:2018-08-19 08:24:10

标签: android android-button

我现在可以拥有一个包含单个图像图标和文本的按钮,如下所示(红色正方形是图像):

enter image description here

<Button
    android:id="@+id/btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@drawable/shadow"
    android:drawableLeft="@drawable/redsquare"
    android:drawablePadding="6dp"
    android:text="Text goes here"
    android:textColor="@android:color/white"
    android:textSize="14dp"
    android:textAllCaps="false"
    android:gravity="left|center" />

但是,我要显示如下所示的按钮(两个小红色正方形是两个不同的图像):

enter image description here

我试图在按钮中添加另一个可绘制对象,但结果与预期不符。请问如何获得与上述按钮相同的结果?

1 个答案:

答案 0 :(得分:1)

更好的方法是使用custom buttonripple effect添加到视图的custom button selector或自定义视图。