【发布时间】:2014-09-01 21:38:00
【问题描述】:
我在 strings.xml 中有一个字符串数组,它是一个颜色名称数组。而且,我在 colors.xml 中列出了与数组项同名的颜色。现在,我正在尝试使用 strings.xml 中的颜色名称(字符串)设置视图的背景。我该怎么做?
<color name="aliceBlue">#F0F8FF</color>
<color name="antiqueWhite">#faebd7</color>
<color name="antiqueWhite1">#ffefdb</color>
<color name="antiqueWhite2">#eedfcc</color>
<color name="antiqueWhite3">#cdc0b0</color>
<color name="antiqueWhite4">#8b8378</color>
<color name="aquaMarine1">#7fffd4</color>
<color name="aquaMarine2">#76eec6</color>
<color name="aquaMarine4">#458b74</color>
<color name="azure1">#f0ffff</color>
<color name="azure2">#e0eeee</color>
<color name="azure3">#c1cdcd</color>
<color name="azure4">#838b8b</color>
颜色.xml
<string-array name="colorNameArray">
<item>AliceBlue</item>
<item>AntiqueWhite</item>
<item>AntiqueWhite1</item>
<item>AntiqueWhite2</item>
<item>AntiqueWhite3</item>
<item>AntiqueWhite4</item>
<item>aquamarine1</item><item>
aquamarine2</item>
<item>aquamarine4</item>
<item>azure1</item>
<item>azure2</item>
<item>azure3</item>
<item>azure4</item>
字符串.xml
请大家帮忙,感谢您的帮助。
【问题讨论】:
-
我认为你必须使用开关。
-
你为什么使用 colorNameArray ??你能解释一下吗?
-
微调器?从列表中选择一种颜色?
-
对于你的古董白色,我建议只是切换它,如果它是适用于 Color.parseColor 的颜色之一,则使用它作为默认值