public static int[] extractColorArray(@ArrayRes int arrayId, Context context) {
String[] choicesString = context.getResources().getStringArray(arrayId);
int[] choicesInt = context.getResources().getIntArray(arrayId);
// If user uses color reference(i.e. @color/color_choice) in the array,
// the choicesString contains null values. We use the choicesInt in such case.
boolean isStringArray = choicesString[0] != null;
int length = isStringArray ? choicesString.length : choicesInt.length;
int[] colorChoices = new int[length];
for (int i = 0; i < length; i++) {
colorChoices[i] = isStringArray ? Color.parseColor(choicesString[i]) : choicesInt[i];
}
return colorChoices;
}
ColorUtils.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:colorpreference
作者:
评论列表
文章目录