On a part of my layout I need to force the background to the same color of the default background color of the light theme (actually Theme.AppCompat.Light).
So I added this attribute : android:background="?android:attr/colorBackground".
But this background color is lighter than the default I have in the rest of my app.
From the android themes.xml, in the holo light theme, ?android:attr/colorBackground targets #android:background_holo_light which is equals to #f3f3f3. But the default background color is more something like #eeeeee, I really wonder where this color came from ?
The problem occurs on Kitkat, I don't have color discrepancy under Gingerbread.
Finally find the answer, for hardware accelerated devices, android:attr/windowBackground points to a gradient, not a plain color like I expected.
So when I use android:background="?android:attr/colorBackground" for on of my view, depending to where it is located in the screen height, we can see a color discrepancy.
The solution is to override windowBackground with colorBackground in the theme :
<item name="android:windowBackground">?android:attr/colorBackground</item>
Related
I will try to explain in detail‚ please help. I opened a new project‚ in the new project the "theme" section was opened twice‚ one light one dark. I added black text to the app ‚the text looked white because my phone is a dark theme. This is very good but incomprehensible. I only have one color.xml file (not for the night version) How did the text change to white? This is fine but the icon (vector ‚xml) I added and gave it a gray color ‚but now it was incomprehensible. The color of the icon changed from gray to black in the dark. I wanted him to change to white. I also opened for Colors.xml for the night. Now that I think there will be no mistakes, nothing has changed. The night is getting black in them.
How can I make an icon (vector ‚xml) gray in light and white in the dark theme?
I have a dark and light "theme" file ‚Do I have to separate the "colors" into dark and light themes?
I hope I was able to explain ‚Thank you so much!
The text's color has changed to white because you didn't set a color, and it's inherits from the default android settings.
If you want to change (customise) the colors depending on the theme, I suggest you to override the colors.xml file for the night mode.
Declare the color that you want for your icon.
colors.xml
<color name="iconColor">#FF808080</color>
colors.xml (night)
<color name="iconColor">#FFFFFFF</color>
In your drawable, you must set this new color.
android:fillColor="#color/iconColor"
It's also a good thing to override the others colors (primary, primaryLight, etc.) to lighter variants.
You can practice here if you want to exercise the theme changed on android (this is in Kotlin, but the same course exists in Java).
I am developing a paint app for android by extending the View class. On onDraw method, I am drawing the background using canvas.drawColor(Color.WHITE) each time onDraw is called and drawing other stuffs on top of it.. Everything is working fine when I am in default light theme but as soon as dark theme is applied to the device, the background of my custom view is changed to black. How can I stop this?
Make sure your app's theme does not inherit from Theme.MaterialComponents.DayNight rather inherits from Theme.MaterialComponents.Light or some version of it to disable night more. If you need to use Theme.MaterialComponents.DayNight theme, then you can specify the a color on values/colors.xml and values-night/colors.xml. The app will use values-night/colors.xml colors for night theme.
Set background color to your custom view don't leave it to the default color. Android changes the default color on theme change.
another solution is to set the theme to
<style name="App.Theme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
but this will lead to always light theme regardless of the system/phone theme.
I'm learning Android development and there's a problem i couldn't find the solution. I'm using a TextInputLayout that works fine with white or light backgrounds, applying the Theme accent color and so on. But, if i use it with a darker background (e.g. dark grey ), it doesn't use the theme colors.
This image shows the TextInputLayout applied with a dark background.
The question is: do i need to style the TextInputLayout directly or create additional statements for the theme?
(obs: i didn't change anything in the TextInputLayout XML yet)
I also tried solutions that i found here from 3/4 years ago, but it looks like deprecated.
Thanks.
android:minSdkVersion="14" android:targetSdkVersion="18"
In theory simple thing. What is the background color for holo.light as I want to use the same color for something else? It's not white neither background_light. Moreover my question is not how to determine its value but what android predefined constant to use (as if one day google change this light background color in holo light, my color would also change).
Btw, transparent color is not the solution in this case. :(
<color name="background_holo_light">#fff3f3f3</color>
You can find this by using the awesome chrome extension Android Resource Navigator.
https://chrome.google.com/webstore/detail/android-resource-navigato/agoomkionjjbejegcejiefodgbckeebo
You should be able to use #android:color/background_holo_light or android.R.color.background_holo_light I think.
I tried
<color name="background_holo_light">#26f3f3f3</color>
It's the right color for the background Holo light Theme
I'm using ActionBarSherlock, but I'm not using any kind of of other theming. My application looks fine in the layout editor, because I'm using a certain color scheme that goes well with the white background shown. Although, when I run my application on a device 2.x, 3.x or 4.x, I get a very light gray color as the background, but it's definitely not white. Am I missing something? I thought the Light theme was a light gray action bar with a white background.
The Sherlock light theme is a copy of Holo.Light, which uses a very light grey as the default background colour.
You can override it to white it you like. In your application theme (create one if you need to which extends Sherlock Light), set the following attribute:
<item name="android:windowBackground">#android:color/white</item>