Jai Soni
Jai Soni

Reputation: 1

Colours of the android app changes whenever I switch to dark mode on my mobile

I am using android studio 4.1. And android version on my physical phone is 10. When I install the app on my phone, the colours that I see on my phone and the colours that are there in the project are very different. I found that whenever I switch off the dark mode on my phone, the colours become same as they are in the project. And whenever I switch to dark mode on my phone, the colours change. I only want the colours which are displayed in light mode on my phone, in both the cases, if dark mode is off or isn't. And one more thing, i am not finding styles.xml in res/values and something like res(generated) is also in the project/app, these are the things which I do not find generally in any project...

Screenshot of values/themes.

Screenshot of app in light mode.

Screenshot of app in dark mode.

Screenshot of Project(in which some things are there that I do not found generally in any project and styles.xml is also not there).

Screenshot of AndroidManifest.xml..

If you want more information to solve this problem, please comment.

Please help

Upvotes: 0

Views: 3775

Answers (3)

Ricardo Solorzano
Ricardo Solorzano

Reputation: 1

I think I have the solution, the same thing happened to me, the chorus of the text of my buttons is white but when I activated the night mode of the cell phone they changed to blue, then I discovered that it is because the default buttons have the white color for the text and I didn't do anything, but even so you have to define a color for them, so I went down to where it says textcolor and I put the color that was @color/white and that's it, that was it, I hope it helps you. Sorry for the bad English I use a translator

Upvotes: 0

I have been facing the same problem and finally find a solution that works over Android 29(Android Q). Some UI's such as MIUI force dark mode that's why they tend to change colors and drawables even some lottie files.

Apply this piece of code into your custom theme;

<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>

Upvotes: 2

CSmith
CSmith

Reputation: 13458

You have used Theme.MaterialComponents.DayNight.DarkActionBar as your app theme parent, changing this to Theme.MaterialComponents.Light.DarkActionBar will change your app to a light theme:

<style name="Theme.Calculator" parent="Theme.MaterialComponents.Light.DarkActionBar">
...

In your AndroidManifest.xml, found in the manifests folder of your Android Studio workspace, please ensure you're referencing your Theme.Calculator theme.

<application ... android:theme="@style/Theme.Calculator" ...>

You should consider leaving the "DayNight" based theme and add a colors.xml to your res/values-night folder. This would allow you to define alternative colors for dark theme, then your app could look great in both dark and light themes.

Learn more about styles and themes at https://developer.android.com/guide/topics/ui/look-and-feel/themes.

Upvotes: 5

Related Questions