Android 更改颜色选择器/文本新建文本材质按钮

Android 更改颜色选择器/文本新建文本材质按钮,android,material-components,Android,Material Components,我需要自定义选择按钮时选择器的文本颜色或背景色,因为文本的颜色太相似,文本会消失 这是我的代码: <android.support.design.button.MaterialButton android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" styl

我需要自定义选择按钮时选择器的文本颜色或背景色,因为文本的颜色太相似,文本会消失

这是我的代码:

  <android.support.design.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            style="@style/Widget.MaterialComponents.Button.TextButton"
            android:text="@string/lbl_forgotten_password"
            android:textColor="@color/gray_text_1"
            android:textSize="14sp" />

您可以使用
选择器解决此问题

在drawable文件夹中创建一个新的xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="@color/text_color" android:drawable="@drawable/button_bg"/>
    <item android:color="@color/text_normal" />
</selector>

之后


您可以使用
选择器解决此问题

在drawable文件夹中创建一个新的xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="@color/text_color" android:drawable="@drawable/button_bg"/>
    <item android:color="@color/text_normal" />
</selector>

之后



android@background不适用于材质按钮。使用tbackgroundTInt或stroke/strokeWidth操纵材质的背景buttonandroid@background不适用于材质按钮。使用tbackgroundTInt或stroke/strokeWidth操纵材质按钮的背景