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

Share:
26,592
Kostadin
Author by

Kostadin

A lot of work :)

Updated on July 05, 2022

Comments

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

  • Kostadin
    Kostadin over 12 years
    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
    Kostadin over 12 years
    None of these gives me DARKGRAY /backcolor of my menu/ android:background="@android:color/background_dark" android:background="@android:color/background_light"
  • Stephan Branczyk
    Stephan Branczyk over 12 years
    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.
  • Kostadin
    Kostadin over 12 years
    Do you know way to get color filter used in this case?
  • Stephan Branczyk
    Stephan Branczyk over 12 years
    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.
  • Dharmendra
    Dharmendra over 12 years
    Instead of background_dark and background_light you can use your custom color by giving alpha,red,green and blue color code.
  • Kostadin
    Kostadin over 12 years
    Yep. But first I have to know colors used in device. Because I want to make my icons with system used colors.
  • Dharmendra
    Dharmendra over 12 years
    There is a similar question here stackoverflow.com/questions/4192798/…
  • Thomas Ausweger
    Thomas Ausweger over 4 years
    You have to free the array afterwards! See: stackoverflow.com/questions/8598414/…
  • temirbek
    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.