如何在我的活动中获得颜色资源的值

Joe*_*Joe 7 string android colors

我需要获取颜色的字符串值.换句话说,我想#ffffffff从像<color name="color">#ffffffff</color>字符串格式的颜色资源中拉出来.有没有办法做到这一点?

ina*_*ruk 18

假设你有:

<color name="green">#0000ff00</color>
Run Code Online (Sandbox Code Playgroud)

这是代码:

int greenColor = getResources().getColor(R.color.green);
String strGreenColor = "#"+Integer.toHexString(greenColor);
Run Code Online (Sandbox Code Playgroud)