如何在 MaterialButton 中的文本右侧添加可绘制对象?

Anu*_*iya 4 android android-layout material-design

我正在这样做

<com.google.android.material.button.MaterialButton
        android:id="@+id/btnProceed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Proceed to enter Gender"
        style="@style/bottomBtnStyle"
        app:icon="@drawable/ic_right_arrow"
        app:iconGravity="textStart"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"/>
Run Code Online (Sandbox Code Playgroud)

但是图标显示在文本的左侧,图标重力对图标位置没有影响。在普通按钮中,我们曾经使用drawableRight来实现相同的目的,但这里没有找到方法。

Pan*_*mar 6

app:icon="@drawable/ic_right_arrow" 
Run Code Online (Sandbox Code Playgroud)

如果你需要显示在左边就可以了。为了正确显示,您app:iconGravity="end"还需要添加。

并确保您使用正确的按钮样式。这意味着bottomBtnStyle的父级必须是Widget.MaterialComponents.Button