Android Material 按钮没有采用原色
Android Material Button is not taking the primary color
关于 Material 按钮的文档说:
For filled buttons, this class uses your theme's ?attr/colorPrimary
for the background tint color and ?attr/colorOnPrimary for the text
color.
但是按钮采用了主题强调色。这是我的应用主题:
<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>
Colors.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">
我不知道我遗漏了哪些文档。
我对 google material 库
有同样的问题
implementation 'com.google.android.material:material:1.0.0-alpha1'
我刚刚用这个
替换了这个库
implementation 'com.google.android.material:material:1.2.0-alpha02'
抱歉造成混淆。只需应用样式:style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Material button">
</com.google.android.material.button.MaterialButton>
关于 Material 按钮的文档说:
For filled buttons, this class uses your theme's ?attr/colorPrimary for the background tint color and ?attr/colorOnPrimary for the text color.
但是按钮采用了主题强调色。这是我的应用主题:
<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>
Colors.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">
我不知道我遗漏了哪些文档。
我对 google material 库
有同样的问题 implementation 'com.google.android.material:material:1.0.0-alpha1'
我刚刚用这个
替换了这个库 implementation 'com.google.android.material:material:1.2.0-alpha02'
抱歉造成混淆。只需应用样式:style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Material button">
</com.google.android.material.button.MaterialButton>