将主题更改为 MaterialComponent 默认的 EditTextPreference 按钮后,现在带有白色文本
After changing the theme to MaterialComponent default EditTextPreference buttons now with white text
我的styles.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight"><!-- MaterialComponents theme -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
我的preferences.xml
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Default EditTextPreference created by default -->
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
结果(按钮上的白色文本)
清空新项目。 com.google.android.material:material:1.1.0
如何修复 EditTextPreference 按钮上的文本颜色?
事实证明,在 1.1.0 版本中,文本颜色取自 colorPrimary
,而不是 colorAccent
。
解决方法:只使用样式 Theme.MaterialComponents.DayNight.Bridge
详情:https://material.io/develop/android/docs/getting-started/#bridge-themes
我的styles.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight"><!-- MaterialComponents theme -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
我的preferences.xml
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Default EditTextPreference created by default -->
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
结果(按钮上的白色文本)
清空新项目。 com.google.android.material:material:1.1.0
如何修复 EditTextPreference 按钮上的文本颜色?
事实证明,在 1.1.0 版本中,文本颜色取自 colorPrimary
,而不是 colorAccent
。
解决方法:只使用样式 Theme.MaterialComponents.DayNight.Bridge
详情:https://material.io/develop/android/docs/getting-started/#bridge-themes