我正在尝试使用此方法以编程方式创建ColorStateList:
I am trying to create a ColorStateList programatically using this:
ColorStateList stateList = new ColorStateList(states, colors);但是我不确定这两个参数是什么.
But I am not sure what are the two parameters.
根据文档:
public ColorStateList (int[][] states, int[] colors)已添加到API级别1
Added in API level 1
创建一个ColorStateList,该列表返回从状态到颜色的指定映射.
Creates a ColorStateList that returns the specified mapping from states to colors.
有人可以解释一下如何创建它吗?
Can somebody please explain me how to create this?
二维状态数组的含义是什么?
What is the meaning of two-dimensional array for states?
推荐答案请参见 developer.android/reference/android/R.attr.html#state_above_anchor 以获得可用状态列表.
See developer.android/reference/android/R.attr.html#state_above_anchor for a list of available states.
如果您想为禁用,未聚焦,未选中状态等设置颜色,只需对这些状态取反:
If you want to set colors for disabled, unfocused, unchecked states etc. just negate the states:
int[][] states = new int[][] { new int[] { android.R.attr.state_enabled}, // enabled new int[] {-android.R.attr.state_enabled}, // disabled new int[] {-android.R.attr.state_checked}, // unchecked new int[] { android.R.attr.state_pressed} // pressed }; int[] colors = new int[] { Color.BLACK, Color.RED, Color.GREEN, Color.BLUE }; ColorStateList myList = new ColorStateList(states, colors);更多推荐
如何以编程方式创建ColorStateList?
发布评论