【发布时间】:2020-06-18 16:02:40
【问题描述】:
我正在为我的应用构建浅色/深色主题。我想为应用程序中的所有按钮使用自定义形状。但是在主题之间交换时,colorAccent 属性不会交换为按钮背景颜色。
在灯光模式下,colorAccent 为橙色,显示为橙色。
但在黑暗模式下,colorAccent 是 Purple 但仍显示 Orange
我知道交换是有效的,因为我可以更改其他颜色并且它们被采用。这只是按钮的形状。
我确定它与形状文件中的<solid android:color="@color/colorAccent" /> 有关。
谁能看出我做错了什么?
轻主题
<resources>
<!--Top level DayNight theme to be used in AndroidManifest.xml-->
<style name="MyCustomTheme" parent="Base.MyCustomTheme"/>
<style name="MyCustomTheme.System.Defaults" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:fontFamily">@font/driver_font_family</item>
</style>
<style name="Base.MyCustomTheme" parent="MyCustomTheme.System.Defaults">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/OffWhite</item>
<!--Component styles-->
<item name="buttonStyle">@style/MyCustomTheme.Button</item>
</style>
</resources>
夜间主题
<resources>
<style name="MyCustomTheme" parent="Base.MyCustomTheme">
<item name="colorPrimary">@color/Green</item>
<item name="colorPrimaryDark">@color/Red</item>
<item name="colorAccent">@color/Purple</item>
<item name="android:windowBackground">@color/BlackDark</item>
</style>
</resources>
rounded_corners.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp" />
<padding android:padding="0dp"/>
<solid android:color="@color/colorAccent" />
</shape>
colors.xml
<resources>
<!--Leaving these here since they are refrenced by the system and other components-->
<color name="colorPrimary">@color/NavyBlue</color>
<color name="colorPrimaryDark">@color/NavyBlueDark</color>
<color name="colorAccent">@color/Orange</color>
<color name="Red">#E84E3C</color>
<color name="Purple">#745EC4</color>
<color name="Green">#2FCC70</color>
<color name="NavyBlue">#34495E</color>
<color name="NavyBlueDark">#2B3D4F</color>
<color name="BlueDark">#394D82</color>
<color name="OffWhite">#EDF1F2</color>
<color name="BlackDark">#262626</color>
</resources>
【问题讨论】:
标签: android material-design android-theme