Android System Color Constants

55,055

Solution 1

You should have a file in res/values called colors.xml, it should look like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="white">#FFFFFF</color>
    <color name="grey">#7A7A7A</color>
    <color name="background">#0044AA</color>
    <color name="bluelight">#449DEF</color>
    <color name="bluedark">#2F6699</color>
    <color name="greenlight">#70C656</color>
    <color name="greendark">#53933F</color>
    <color name="orangelight">#F3AE1B</color>
    <color name="orangedark">#BB6008</color>
    <color name="black">#000000</color>
</resources>

Then you can just call the color in xml like this:

android:background="@color/greenlight"

Solution 2

You can use things like "@color/white", or for android system constants, "@android:color/holo_red_light". Alternatively if you want more control, you can always define a common background in a drawable and set the background to "@drawable/mydrawable"

List of resources available for android:color here (like background_dark): http://developer.android.com/reference/android/R.color.html

Solution 3

check out this page: http://android-er.blogspot.com/2010/03/using-color-in-android.html

You can use: "@android:color/white" in your xml. I imagine that a few other common colors are supported, but I don't know for sure which ones.

The preferred solution is generally to create your own colors.xml resource file and reference the ones that you put inside there.

Solution 4

used like this : android:background="#FF00FF"

Share:
55,055
zam664
Author by

zam664

Updated on July 25, 2022

Comments

  • zam664
    zam664 almost 2 years

    Android programming is driving me crazy. The XML or programmable ways for GUI development is making a right old dogs breakfast of the code--some stuff here, some stuff there.

    My current frustration is trying to keep it all XML and I would like to set the background color of the TextView the same color as the background color of a Button without having to specify the exact color code. I would like to use a system constant, something like java.awt.SystemColor.control, but specified in XML.

    Is there anyway of doing this without having to respecify a bunch of stuff? I'm looking for a solution like: android:background="{Insert constant here}".