【发布时间】:2020-04-16 15:07:43
【问题描述】:
我有点困惑。我在我的应用程序中使用了 DayNight 主题(使用 AppCompatDelegate.setDefaultNightMode()),但无法在我的 MainActivity 中使用它。
MainActivity(扩展 FragmentActivity)看起来从未设置为深色主题 - 它始终保持浅色主题。
我尝试直接在我的 MainActivity 中设置主题:
@Override
protected void onCreate(Bundle savedInstanceState) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
super.onCreate(savedInstanceState);
// create main activity.
}
但这不起作用。
我已经使用 ?attr/colorReference 正确设置了布局文件中的所有颜色。有谁知道这里出了什么问题?
编辑: 我的styles.xml如下:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!--Default typeface and colors:-->
<item name="android:typeface">monospace</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorAccentDarker">@color/colorAccentDarker</item>
<item name="colorAccentDarker_80percent">@color/colorAccentDarker_80percent</item>
<!--Show people's own wallpaper background-->
<item name="android:windowShowWallpaper">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
【问题讨论】:
-
你能告诉我们你的
style.xml吗?
标签: android android-fragmentactivity theme-daynight