9

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:

light mode

So now, when I switch my phone to dark mode, this happens:

dark mode

How can I change the colors that are being displayed in dark mode?

Alcachofra
  • 135
  • 1
  • 1
  • 6

2 Answers2

27

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.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
nima
  • 432
  • 5
  • 6
  • If you do not manually color some of the views in the layout, it uses the default value. This default value is defined in the manifest theme. For example theme = "...". You can in the theme directory or in the style directory . Create a style tag and change the default values(Ex. primaryColor) inside and give it a manifest theme. – nima Sep 03 '21 at 11:57
4

enter image description here

https://developer.android.com/guide/topics/resources/providing-resources

Use the folders:

/values/
/values-night/

It mentions it here as well: https://developer.android.com/guide/topics/ui/look-and-feel/darktheme#config-changes

"night-qualified resources"

Your themes and styles should avoid hard-coded colors or icons intended for use under a light theme. You should use theme attributes (preferred) or night-qualified resources instead.
Blundell
  • 75,855
  • 30
  • 208
  • 233