Belphegor
Belphegor

Reputation: 1843

How do I control what colors are used when a user switches between Light and Dark mode in Android

Suppose I have my own two custom defined themes in the styles.xml, one for Dark and one for Light. When a user goes into their smartphones settings and change to dark mode, how do I have my application use my own custom dark theme? Same with my Light theme.

In general, I suppose my question is more like how do I control what color my application uses when a user changes between light and dark mode. I do not want to use the default colors that come in each mode.

Upvotes: 2

Views: 1265

Answers (1)

EraftYps
EraftYps

Reputation: 818

You can override the colors that you use in your layout and put them in values-night/colors.xml. So, in light theme values/colors.xml will be used and in the night theme, values-night/colors.xml will be used.

Let's say you have a color assigned to a button, you write following line, make sure the color name is same:

values/colors.xml

<color name="colorButton">#6d85c9</color>

values-night/colors.xml

<color name="colorButton">@color/colorWhite</color>

And then you can assign the color to the button you do normally.

Let me know if you have more questions.

Upvotes: 2

Related Questions