我正在尝试构建一个带有边框按钮的布局,如下所示(预期行为)。从 Material design 文档中,我了解到 Outlined Material Button 似乎非常适合我的目的。我在我的布局中定义了按钮,提供了描边宽度和描边颜色,但它没有显示任何边框,我做错了什么?
<com.google.android.material.button.MaterialButton
android:id="@+id/material_text_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Change name"
android:background="@android:color/transparent"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/listTextView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/listTextView2"
app:layout_constraintTop_toTopOf="@+id/listTextView2"
app:strokeColor="@color/green"
app:strokeWidth="10dp" />
预期行为:
当前行为:
最佳答案
只需将此属性添加到您的 MaterialButton
android:theme="@style/Theme.MaterialComponents"
避免将它添加到您的主题中。
例子:
<com.google.android.material.button.MaterialButton
android:id="@+id/material_text_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/Theme.MaterialComponents"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Change name"
android:background="@android:color/transparent"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/listTextView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/listTextView2"
app:layout_constraintTop_toTopOf="@+id/listTextView2"
app:strokeColor="@color/green"
app:strokeWidth="10dp" />
关于android - Outlined MaterialButton 不显示任何边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55381108/