Implement night mode on Android

0

I understand that Android is a night mode is to say that it differs if it is day or night, my question is How to get that data and thus be able to change from a clear subject to a dark subject?

Update

The problem that arises after finding how to implement the day / night theme is that when the device rotates it does not just look the same.

    
asked by Webserveis 26.07.2016 в 15:08
source

1 answer

0

Looking at the official documentation can be obtained from UiModeManager .

I've also found that tutorial that implements it from a simple way.

Summing up: Android Day Night mode, you can differentiate with the suffix -night and in the definition of the theme Theme.AppCompat.DayNight.DarkActionBar the colors of the night interface will be in values-night/colors.xml

To set it to detect it automatically

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);

If you want to force it to be seen in Night mode

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

If you want to see it in the default mode it means day mode.

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

Downloadable tutorial example: DayNightThemeExample

    
answered by 26.07.2016 / 15:54
source