Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Colors in Dark Mode

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?

like image 552
Alcachofra Avatar asked Feb 01 '26 11:02

Alcachofra


2 Answers

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.

like image 128
nima Avatar answered Feb 03 '26 05:02

nima


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.
like image 33
Blundell Avatar answered Feb 03 '26 05:02

Blundell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!