首页 > 解决方案 > Android Material Button没有采用原色

问题描述

关于 Material Button 的文档说:

对于填充按钮,此类使用主题的 ?attr/colorPrimary 作为背景色,使用 ?attr/colorOnPrimary 作为文本颜色。

但 Button 采用 Theme 强调色。这是我的应用主题:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

按钮代码:

<com.google.android.material.button.MaterialButton

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:text="Material button">

        </com.google.android.material.button.MaterialButton>

颜色.xml:

<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B</color>
</resources>

显现:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

我不知道我对文档缺少什么。

标签: androidmaterial-components-android

解决方案


我对谷歌材料库有同样的问题

 implementation 'com.google.android.material:material:1.0.0-alpha1'

我刚刚用这个替换了这个库

 implementation 'com.google.android.material:material:1.2.0-alpha02'

推荐阅读