radiobutton动态设置drawable
StateListDrawable stateListDrawable=new StateListDrawable();stateListDrawable.addState(new int[]{android.R.attr.state_checked},getContext().getResources().getDrawable(R.drawable.ic_launcher));
stateListDrawable.addState(new int[]{},getContext().getResources().getDrawable(R.drawable.ic_launcher));
radiobutton.setButtonDrawable(stateListDrawable);
1,StateListDrawable extends DrawableContainer
DrawableContainer extends Drawable
2,addState(int[] stateSet, Drawable drawable)
引用的是android.R.attr.state_checked,注意是state_checked,而不是checked
3,空数组为默认4,设置的是ButtonDrawable,而不是Drawable
页:
[1]