我只是想尝试新的主题风格(Theme.AppCompat.DayNight
),它有效,但它搞砸了我的卡片背景。
如何更改卡片背景?
这是我的v21/styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@android:color/transparent</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowActionBar">false</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
我的colors- night限定符的colors.xml
<resources>
<color name="primary">#ff01dc53</color>
<color name="primaryDark">#ff01dc53</color>
<color name="accent">#01dc53</color>
</resources>
MyApplication类:
package com.cyanogen.unofficial.dashboard.util;
import android.app.Application;
import android.app.UiModeManager;
import android.content.Context;
import android.support.v7.app.AppCompatDelegate;
/**
* Created by Shiva on 14-03-2016.
*/
public class MyApplication extends Application {
static {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
}
@Override
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
}
}
屏幕截图:
答案 0 :(得分:1)
根据release notes of the revision 23.2.1 of the Support Library,此版本已修复issue 194497,为CardView
添加了一个黑暗主题。这是通过使用CardView.Dark
样式完成的。
所以你要在values/styles.xml
:
<style name="CardView.DayNight" parent="CardView.Light />
在您的values-night/styles.xml
:
<style name="CardView.DayNight" parent="CardView.Dark" />
然后使用CardView
style="@style/CardView.DayNight"