android 中的自定义主题和颜色

Custom themes and colors in android

我可以为两个不同的主题定义两个完全不同的colors.xml吗?例如,在我的例子中,我们在调色板中使用了更多不同的颜色,这些颜色由标准(android:colorPrimary、android:colorAccent、android:colorBackground 等)在主题中定义。希望我的问题很清楚。如果不是,请在评论中问我。

好的,经过一番搜索,我找到了这样的解决方案。 Designer 不想使用 colorPrimary 等,所以我在 attrs 中添加我的自定义属性,如下所示:

<attr name="colorExperiment" format="color"/>

在此之后,我在主题的样式中添加了这个属性,如下所示:

 <style name="DarkTheme" parent="AppTheme.NoActionBar">
    <item name="android:windowAnimationStyle">@null</item>
    <item name="android:windowBackground">@color/onyx</item>
    <item name="colorExperiment">@color/onyx</item>
</style>

并在布局中使用,例如:

<TextView
   android:id="@+id/auth_caption"
   android:includeFontPadding="false"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_centerHorizontal="true"
   android:gravity="center"
   android:textSize="34dp"
   android:text="@string/auth_caption"
   android:textColor="?colorExperiment"
 />