【问题标题】:Change color selector/text new Text MaterialButton更改颜色选择器/文本新文本 MaterialButton
【发布时间】:2019-07-10 22:50:10
【问题描述】:

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

这是我的代码:

  <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" />

看起来是这样的:

【问题讨论】:

    标签: android material-components


    【解决方案1】:

    你可以使用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.support.design.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:background="@drawable/your_xml_file_name"
            android:text="@string/lbl_forgotten_password"
            android:textSize="14sp" />
    

    【讨论】:

    • android@background 不适用于材质按钮。使用 tbackgroundTInt 或 stroke/strokeWidth 来操作材质按钮的背景
    猜你喜欢
    • 1970-01-01
    • 2020-11-23
    • 2012-04-16
    • 2015-05-27
    • 2023-01-12
    • 1970-01-01
    • 2012-10-26
    • 2014-05-16
    • 2021-08-07
    相关资源
    最近更新 更多