有没有办法获得颜色代码例如
<resources>
<color name="colorPrimary">#ff000000</color>
<color name="colorPrimaryDark">#ff000000</color>
<color name="colorAccent">#ff008dcd</color>
<color name="colorControlHighlight">#ff757575</color>
<color name="colorControlNormal">#ff57beee</color>
</resources>
所以我想得到颜色名称和颜色代码
我们来看第一个代码所以它是colorPrimary,代码是#ff000000
注意此代码不是color.xml,但它是一个字符串,我想从中获取名称和颜色代码
没有alpha,你可以这样做:
int colorPrimary = getResources().getColor(R.color.colorPrimary);
String strColorPrimary = "#"+Integer.toHexString(colorPrimary);
类似的问题在这里回答:Android get list of string resources from special file
因此,您可以尝试枚举案例中的颜色资源,以查找与特定值匹配的名称。