【发布时间】:2021-08-19 12:52:22
【问题描述】:
我想创建带有文本和图标的按钮,都左对齐。
我正在使用app:iconGravity="textEnd" 将图标直接放在按钮文本之后,但是如果我使用android:gravity="left" 将文本位置更改为左侧,则图标将保持在旧的居中位置
我的布局-xml:
<com.google.android.material.button.MaterialButton
android:id="@+id/listentry_button"
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
app:icon="@drawable/ic_arrow_straight_right"
app:iconGravity="textEnd"
android:gravity="left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="@string/account_data_personal_data"
android:textColor="@color/primaryTextColor"
app:iconTint="@color/secondaryColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
知道如何使用材料按钮来实现这一点,还是不可能?
【问题讨论】:
-
为什么不尝试使用线性布局而不是 Material 按钮?
标签: android material-components-android