我的 String.xml 文件中有颜色,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="txtEmail">Email </string>
<string name="txtPin">Pin Code</string>
<string name="lblProtected"> Protected</string>
<color name="MiscellaneousPercent">#ffff992b</color>
<color name="MusicPercent">#ffffdd58</color>
<color name="PicturesPercent">#ff48aa71</color>
<color name="eBooksPercent">#ff00cff9</color>
<color name="DocumentsPercent">#ff019df2</color>
</resources>
我想在我的项目中使用这些颜色,以便通过代码迭代颜色。
public class BreakDownBar extends View {
public BreakDownBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
for (int i = 0; i < 5; i++) {
Paint paint = new Paint();
paint.setColor(/*I want to use the colors HERE*/);
}
}
}
如何使用上述onDraw
方法中的颜色SetColor()
?我可以将 String.XML 文件中的颜色放在一个数组中吗?谁能帮我?