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

Viewed 29

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.

1 Answers

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.

Related