user12359279
user12359279

Reputation:

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?

Upvotes: 6

Views: 6080

Answers (4)

Mahdi Safarmohammadloo
Mahdi Safarmohammadloo

Reputation: 553

(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>

Upvotes: 3

user12359279
user12359279

Reputation:

Just change both theme files with

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

Upvotes: 8

RaphaWOW
RaphaWOW

Reputation: 72

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

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

Upvotes: 0

Wahdat Jan
Wahdat Jan

Reputation: 4156

Add this in your App theme

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

Upvotes: 3

Related Questions