我试图访问colors.xml中的每个值,但R/color类中的int(十六进制)值与colors.xml中定义的对应值不匹配。下面是一些样本值:colors.xml在gen/R文件中没有生成正确的值?
R/color (all of which starts with 0x7f0400...):
public static final int AliceBlue=0x7f04002d;
public static final int AntiqueWhite=0x7f040023;
public static final int Aqua=0x7f04007d;
public static final int Aquamarine=0x7f040062;
public static final int Azure=0x7f04002b;
...
But in colors.xml (all of which starts with #00...):
<color name="AliceBlue">#F0F8FF</color>
<color name="AntiqueWhite">#FAEBD7</color>
<color name="Aqua">#00FFFF</color>
<color name="Aquamarine">#7FFFD4</color>
<color name="Azure">#F0FFFF</color>
当我用“R.color.Red”例如,颜色不输出红色引用其
id
得到Color
,这也对于colors.xml中定义的其他颜色也是如此。我仔细检查了colors.xml的值,它们是正确的。如何使用它来为我的Spannable字符串的某些字符着色:“spnStr”,spnStr.setSpan(new ForegroundColorSpan(R.color.Red),i,i + 1,android.text.Spannable.SPAN_EXCLUSIVE_INCLUSIVE); – jerryh91@ jerryh91查看我更新的答案,了解如何引用颜色 – codeMagic