如何在 Android 11 中禁用夜间模式?
How can I disable Night Mode in Android 11?
我试过删除夜theme.xml
,我试过在夜主题中进行颜色更改。我也试过了
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
但其中 none 有效。
这是我的 theme.xml
:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.app" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/light_blue</item>
<item name="colorPrimaryVariant">@color/light_blue</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
我该怎么做?
将此添加到您的应用主题中
<item name="android:forceDarkAllowed">false</item>
在您的样式声明中,尝试将父项直接更改为 Light
,如下所示:
<style name="Theme.app" parent="Theme.AppCompat.Light.NoActionBar">
只需将两个主题文件更改为
<style name="Theme" parent="Theme.MaterialComponents.Light.NoActionBar">
(以上两个答案!并且它适用于 Jetpack Compose)
将两个主题文件更改为
<style name="Theme.PathFinder" parent="Theme.MaterialComponents.Light.DarkActionBar">
并将其添加到两个主题文件中
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
我试过删除夜theme.xml
,我试过在夜主题中进行颜色更改。我也试过了
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
但其中 none 有效。
这是我的 theme.xml
:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.app" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/light_blue</item>
<item name="colorPrimaryVariant">@color/light_blue</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
我该怎么做?
将此添加到您的应用主题中
<item name="android:forceDarkAllowed">false</item>
在您的样式声明中,尝试将父项直接更改为 Light
,如下所示:
<style name="Theme.app" parent="Theme.AppCompat.Light.NoActionBar">
只需将两个主题文件更改为
<style name="Theme" parent="Theme.MaterialComponents.Light.NoActionBar">
(以上两个答案!并且它适用于 Jetpack Compose)
将两个主题文件更改为
<style name="Theme.PathFinder" parent="Theme.MaterialComponents.Light.DarkActionBar">
并将其添加到两个主题文件中
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>