Hello fellow developers.
I’ve developed and Android App using Android Studio, but I only took into account the layout themes for light mode. Here’s how it looks:
So now, when I switch my phone to dark mode, this happens:
How can I change the colors that are being displayed in dark mode?
Advertisement
Answer
In res/values/colors
There are two colors
colors.xml
colors.xml(night)
If night does not exist, you can make it as follows:
Right click on the values
folder.
Next New
. Then Values Resource file
Enter the colors
in the file name
field
And enter the values-night
in the directory name
field.
In colors.xml, select the colors that are for the light, such as:
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryVariant">#303F9F</color> <color name="colorButton">#303F9F</color>
In colors.xml(night), set the colors for the night(Same name as colors):
<color name="colorPrimary">#212121</color> <color name="colorPrimaryVariant">#000000</color> <color name="colorButton">#10ffffff</color>
Now if in layout, for example:
<Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: background = "@color/colorButton" />
It is selected according to what you put in the light and night colors.