Change background color according to the phone mode – Android Studio in Java

Issue

I’m trying to build a Java application with Android Studio. I plan to make 2 versions: a day version and a night version. How can I change the background of my xml file according to the mode it is set? That is, if it is day, the background must be white, if it is night it must be blue.

Solution

There are a few ways to go about this, one way is the following:

You need to create 2 files under the res/values/colours. One as the default and one for night.

In each of those files create something like the following:

<color name="application_background">HEX_CODE_VALUE</color>

Then in your desired layout simply add application_background as the background colour – assuming you are using XML layouts.

Answered By – CodeGorilla

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published