简体   繁体   中英

How can I disable Night Mode in Android 11?

I tried to delete night theme.xml , and I tried to make color changes in night theme. I also tried

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

But none of these worked.

This is my 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>

How can I do it?

Just change both theme files with

<style name="Theme" parent="Theme.MaterialComponents.Light.NoActionBar">

Add this in your App theme

<item name="android:forceDarkAllowed">false</item>

In the declaration of your style, try changing the parent directly to Light as follows:

<style name="Theme.app" parent="Theme.AppCompat.Light.NoActionBar">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM