android - 概述的 MaterialButton 不显示任何边框
问题描述
我正在尝试使用带边框的按钮构建布局,如下所示(预期行为)。从 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" />
推荐阅读
- javascript - 从 Angular 中的 API 加载 json 数据的问题
- python - pyto unittest 私有方法
- python - Tkinter,其他类的功能
- 3d - 为什么我无法打开这个 GLTF 3D 文件?
- purescript - 是否可以将类型类约束放在(数据)类型参数上?
- javascript - 如何在Active Ionic Vue时每次在安装上调用函数?
- android - java.lang.Object 类型无法解析。它是从所需的 .class 文件 android studio 中间接引用的
- python - 访问类型。文字值
- scala - 获取Scala3宏中的类型信息
- image - 小部件中的颤振数据不显示,仅在单击后退按钮并返回小部件页面时显示