Search code examples
javaandroiddarkmode

Can't disable dark mode in android below 29


I'm new to android, creating an android app for marshmallow to current version users, In my app I try to disable dark mode but it is not working for me.

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar">

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);

 <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>

I tried this methods but it is not worked for me. How can I achieve this.


Solution

  • The simplest way to disable Dark Mode is

    android:forceDarkAllowed="false"
    

    in your main_activity.xml root Layout also,

    Override Resource in layout-v29