Java How to turn off darkmode for my app in android studio

Java How to turn off darkmode for my app in android studio

To turn off dark mode for your app in Android Studio, you can use the setDefaultNightMode method of the AppCompatDelegate class and set it to AppCompatDelegate.MODE_NIGHT_NO.

Here's an example of how you can do this in the onCreate method of your Application class:

‮er‬fer to:lautturi.com
import androidx.appcompat.app.AppCompatDelegate;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Turn off dark mode
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
}

This code will turn off dark mode for your app. Note that this will override any system-level dark mode settings, and your app will always use the light theme.

If you want to allow the user to choose whether to use dark mode or not, you can use the MODE_NIGHT_FOLLOW_SYSTEM value instead of MODE_NIGHT_NO. This will allow the app to follow the system-level dark mode setting.

Here's an example of how you can use the MODE_NIGHT_FOLLOW_SYSTEM value to allow the user to choose dark mode:

import androidx.appcompat.app.AppCompatDelegate;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Follow the system-level dark mode setting
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
    }
}

This code will allow the user to choose whether to use dark mode or not, based on the system-level dark mode setting.

Created Time:2017-11-03 23:27:08  Author:lautturi