13

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 is BLACK, menu background color is DARKGREY. Values from android:color/ in device is: only BLACK and WHITE backgrounds.

Tamás
  • 47,239
  • 12
  • 105
  • 124
Kostadin
  • 2,499
  • 5
  • 34
  • 58

3 Answers3

16

You can get android system color using

android:textColor="@android:color/black"

And this is working fine

Dharmendra
  • 33,296
  • 22
  • 86
  • 129
  • None of these gives me DARKGRAY /backcolor of my menu/ android:background="@android:color/background_dark" android:background="@android:color/background_light" – Kostadin Dec 12 '11 at 10:32
  • Instead of background_dark and background_light you can use your custom color by giving alpha,red,green and blue color code. – Dharmendra Dec 13 '11 at 03:46
  • Yep. But first I have to know colors used in device. Because I want to make my icons with system used colors. – Kostadin Dec 13 '11 at 07:54
  • There is a similar question here http://stackoverflow.com/questions/4192798/how-to-get-android-system-colors – Dharmendra Dec 13 '11 at 08:45
  • `resource android:color/yellow not found` system doesn't have yellow? even more interesting: `error: resource android:color/red is private.` – temirbek Feb 12 '21 at 07:45
12

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);
Community
  • 1
  • 1
Kostadin
  • 2,499
  • 5
  • 34
  • 58
  • You have to free the array afterwards! See: https://stackoverflow.com/questions/8598414/get-an-edittexts-default-color-value-from-theme – Thomas Ausweger Feb 26 '20 at 14:15
0

It might just be setting a color filter on whatever the base color of the device is. That may be why you're not getting the base color you were expecting.

This is just a theory, I haven't verified it yet. Either that, or the base color for the theme you're looking is stored in a slightly different location. That's also a possibility.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • I'm trying to use system colors for background in my dialogs, views, toolbars. My idea is to use plain icons with color filter. – Kostadin Dec 12 '11 at 10:30
  • Have 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. – Stephan Branczyk Dec 12 '11 at 10:37
  • Do you know way to get color filter used in this case? – Kostadin Dec 12 '11 at 10:38
  • No, 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. – Stephan Branczyk Dec 12 '11 at 10:42