在这种情况下,我相信只有按钮中文本的颜色已更改,它具有textColorPrimary的颜色值。textColorPrimary和colorAccent相同的可能性
我在AppTheme
中的styles.xml
看起来像这样:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
我在清单中将其设置为:
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
根据https://material.io/develop/android/components/应用于我的小部件的默认颜色应该是定义的colorPrimary,但是我选择的是colorAccent作为默认颜色。例如,此按钮:
<com.google.android.material.button.MaterialButton
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginEnd="56dp"
android:text="login"
app:cornerRadius="5dp"
app:elevation="0dp"
app:fontFamily="@font/gotham_bold" />
“>
我是否为此项目缺少一个特定的配置,因此该按钮具有显示colorPrimary
而非colorAccent
的按钮?
styles.xml中的My AppTheme看起来像这样:
在这种情况下,我相信只有按钮中文本的颜色已更改,它具有textColorPrimary的颜色值。textColorPrimary和colorAccent相同的可能性
使用材料成分库1.1.0
MaterialButton
的默认样式是:
版本<style name="Widget.MaterialComponents.Button" parent="Widget.AppCompat.Button"> <item name="backgroundTint">@color/mtrl_btn_bg_color_selector</item> <!-- .... --> </style>
从...开始
1.1.0
@color/mtrl_btn_bg_color_selector
基于?attr/colorPrimary
:<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="?attr/colorPrimary" android:state_enabled="true"/> <item android:alpha="0.12" android:color="?attr/colorOnSurface"/> </selector>
在版本
1.0.0
中,选择器基于1.0.0
:
?attr/colorAccent
在这种情况下,我相信只有按钮中文本的颜色已更改,它具有textColorPrimary的颜色值。textColorPrimary和colorAccent相同的可能性
使用材料成分库1.1.0