Search code examples
androidstringcolors

how can i get the value of a color resource in my activity


i need to get the string value of a color. in other words i want to pull the #ffffffff from a color resource like <color name="color">#ffffffff</color> in string format. is there any way of doing this?


Solution

  • Assuming you have:

    <color name="green">#0000ff00</color>
    

    And here is code:

    int greenColor = getResources().getColor(R.color.green);
    String strGreenColor = "#"+Integer.toHexString(greenColor);