private StateListDrawable addStateDrawable(Context context, int idNormal, int checkId) { StateListDrawable sd = new StateListDrawable(); Drawable normal = idNormal == -1 ? null : context.getResources().getDrawable(idNormal); Drawable check = checkId == -1 ? null : context.getResources().getDrawable(checkId); //注意该处的顺序,只要有一个状态与之相配,背景就会被换掉 //所以不要把大范围放在前面了,如果sd.addState(new[]{},normal)放在第一个的话,就没有什么效果了 sd.addState(new int[]{android.R.attr.state_checked}, check); sd.addState(new int[]{}, normal); return sd; }
android java 代码创建 selector
最新推荐文章于 2022-04-13 08:45:22 发布