Java纯代码设置CheckBox的样式

其实这些并不是只是CheckBox的样式,我想用纯代码写的是点击一个控件,然后该图片的背景等会改变。

CheckBox是一个非常典型的东西,

不说了 直接上代码:

StateListDrawable drawable = new StateListDrawable ( );
		drawable.addState ( new int[]
		{ android.R.attr.state_checked } , checkbox_true );//checkbox_true 是设置的图片,代表点击之后出现的情况
		drawable.addState ( new int[]
		{ android.R.attr.state_selected } , checkbox_true );
		drawable.addState ( new int[]
		{ android.R.attr.state_pressed } , checkbox_true );
		drawable.addState ( new int[]
		{ -android.R.attr.state_checked } , checkbox_false );
		drawable.addState ( new int[]
		{ -android.R.attr.state_selected } , checkbox_false );
		drawable.addState ( new int[]
		{ -android.R.attr.state_pressed } , checkbox_false );
rember_password_checkBox.setButtonDrawable ( drawable );


你可能感兴趣的:(androi,发现,解决)