How can I disable Night Mode in Android 11?
Asked Answered
F

4

6

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?

Floreated answered 12/2, 2021 at 6:47 Comment(0)
F
8

Just change both theme files with

<style name="Theme" parent="Theme.MaterialComponents.Light.NoActionBar">
Floreated answered 29/6, 2021 at 12:53 Comment(0)
R
3

Add this in your App theme

<item name="android:forceDarkAllowed">false</item>
Rother answered 12/2, 2021 at 6:52 Comment(0)
C
3

(Both above answers ! and it works in jetpack compose)

Change both theme files with

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

And add this in both theme files

<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
Calamus answered 4/8, 2021 at 3:2 Comment(0)
T
0

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

<style name="Theme.app" parent="Theme.AppCompat.Light.NoActionBar">
Tiebout answered 12/2, 2021 at 16:24 Comment(2)
Still Not WorkingFloreated
@Faizan It does not work on Xiaomi devices u should add this code to your them <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>Prolific

© 2022 - 2024 — McMap. All rights reserved.