How to get Android system Colors?
26,592
Solution 1
Thanks for rekire :)
Finally I have the answer: Android: How to get background color of Activity in Java?
TypedArray array = getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground,});
int backgroundcolor = array.getColor(0, 0xFF00FF);
Solution 2
You can get android system color using
android:textColor="@android:color/black"
And this is working fine
![Kostadin](https://i.stack.imgur.com/68JX5.png?s=256&g=1)
Comments
-
Kostadin almost 2 years
I'm searching way to get Android system colors - color theme used in device.
Using
android:color/
I didn't get correct colors. For example: background color in my device isBLACK
, menu background color isDARKGREY
. Values fromandroid:color/
in device is: onlyBLACK
andWHITE
backgrounds. -
Kostadin over 12 yearsI'm trying to use system colors for background in my dialogs, views, toolbars. My idea is to use plain icons with color filter.
-
Kostadin over 12 yearsNone of these gives me DARKGRAY /backcolor of my menu/ android:background="@android:color/background_dark" android:background="@android:color/background_light"
-
Stephan Branczyk over 12 yearsHave you tried making your WHITE color darker with a color filter until it replicates your DARKGREY? Chances are, your plain icons will also be black and white, so you should be able to replicate the black and darkgrey perfectly I think.
-
Kostadin over 12 yearsDo you know way to get color filter used in this case?
-
Stephan Branczyk over 12 yearsNo, I'm sorry. I'd only be guessing and trying different color filters until I got to the right one. Hopefully, someone else has a quicker way to get to that same information.
-
Dharmendra over 12 yearsInstead of background_dark and background_light you can use your custom color by giving alpha,red,green and blue color code.
-
Kostadin over 12 yearsYep. But first I have to know colors used in device. Because I want to make my icons with system used colors.
-
Dharmendra over 12 yearsThere is a similar question here stackoverflow.com/questions/4192798/…
-
Thomas Ausweger over 4 yearsYou have to free the array afterwards! See: stackoverflow.com/questions/8598414/…
-
temirbek over 3 years
resource android:color/yellow not found
system doesn't have yellow? even more interesting:error: resource android:color/red is private.