Android: how to handle day / night themes

I am creating an Android application and I need to have two different themes for day and night modes: different colors and different designs.

What's the best way to do this?

I noticed a service called UiModeManager, but I'm not sure if it behaves the way I expect. I placed two different bitmaps (with the same name) in drawable-mdpi and drawable-night-mdpi, and I created an Activity that shows this bitmap.

I tried to switch day / night mode by inserting onCreate ():

    UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);

      

But Android always shows the "day" version.

Any suggestion or hint would be appreciated.

Thank you, Maurizio

+3


source to share


1 answer


The HoneycombGallery Sample has a day / night switch for theme (background + blueprints, etc.). They only defined two themes and set the code to setTheme()

. Maybe this will help you



Edit: As per the docs setNightMode () "Changes to night mode are only effective if the device has car or table mode enabled."

+1


source







All Articles