android - Outlined MaterialButton 不显示任何边框

标签 android button material-design

我正在尝试构建一个带有边框按钮的布局,如下所示(预期行为)。从 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" />

预期行为:

enter image description here

当前行为:

enter image description here

最佳答案

只需将此属性添加到您的 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/

相关文章:

java - 无法在基于PC的Java服务器上运行我的android客户端

java - Android:下载 flickr 图像

java - 使用按钮停止和开始循环

android-studio - 无法在android studio中导入Material Design Library

java - 系统覆盖android 4.0

java - Android Java - Joda Date 在 Eclipse/Emulator 中运行缓慢 -

android - MonkeyTalk Android Detect String Containing\n for Button Tap

actionscript-3 - 单击按钮后开始下载的 AS3 功能!

android - 向 FloatingActionButton 添加多个行为

javascript - react MUI : Persistent + Responsive drawer