Android 为不同的主题配置不同的颜色

Android 为不同的主题配置不同的颜色,android,android-theme,Android,Android Theme,我正在尝试配置DayNight主题 我的值/style.xml和(值/style.xml)是: @颜色/原色 @颜色/原色暗 @颜色/颜色重音 假的 真的 和colors.xml是: <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.DayNight"> <!-- Customize your them

我正在尝试配置DayNight主题

我的值/style.xml和(值/style.xml)是:


@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
colors.xml是:

<resources>
  <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.AppCompat.DayNight">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  </style>
  <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
  <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
</resources>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="lSun">#ff9800</color>
    <color name="lMoon">#3f51b5</color>
    <color name="lMoonDark">#4f9fbd</color>
</resources>

#008577
#00574B
#D81B60
#ff9800
#3f51b5
#4f9fbd
现在,就像

 <TextView
              android:id="@+id/mr_icon"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/longi"
              android:layout_marginStart="16dp"
              android:layout_marginTop="5dp"
              android:layout_toEndOf="@+id/sunset"
              android:fontFamily="@font/weathericons"
              android:paddingTop="-2dp"
              android:text="@string/moonrise"
              android:textAlignment="center"
              android:textAppearance="@android:style/TextAppearance.Material.Menu"
              android:textColor="@color/lMoon"
              android:textSize="14sp" />

在这里,我希望光明主题使用
@color/lMoon
,黑暗主题使用
@color/lMoonDark


如何实现这一点?

制作两种样式,并将所需样式提供给TextView

<style name="MyTextView" parent="@android:style/TextAppearance.Small">
   <item name="android:layout_width">wrap_content</item>
   <item name="android:layout_height">wrap_content</item>
   <item name="android:textColor">@android:color/white</item>
   <item name="android:textSize">12sp</item>
</style>

<TextView
          style="@style/MyTextView"
          android:id="@+id/mr_icon"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/longi"
          android:layout_marginStart="16dp"
          android:layout_marginTop="5dp"
          android:layout_toEndOf="@+id/sunset"
          android:fontFamily="@font/weathericons"
          android:paddingTop="-2dp"
          android:text="@string/moonrise"
          android:textAlignment="center"
          android:textAppearance="@android:style/TextAppearance.Material.Menu"
          android:textColor="@color/lMoon"
          android:textSize="14sp" />

包装内容
包装内容
@android:彩色/白色
12便士