自定义 checkbox 新玩法 ?
编写
drawable/selector_checkbox_voice.xml
<?xmlversion="1.0"encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/ic_voice_off"android:state_checked="true"/><itemandroid:drawable="@drawable/ic_voice_on"android:state_checked="false"/><itemandroid:drawable="@drawable/ic_voice_off"/></selector>第二步:style
VoiceCheckboxTheme
<!--自定义的checkbox--><stylename="VoiceCheckboxTheme"parent="@android:style/Widget.CompoundButton.CheckBox"><itemname="android:button">@drawable/selector_checkbox_voice</item></style>第三步:布局文件里
<CheckBoxandroid:id="@+id/cb_voice"//这里使用android:layout_width="@dimen/dp21"android:layout_height="@dimen/dp28"android:gravity="center"android:layout_marginLeft="@dimen/dp30"/>第四步:效果
看左边第二个
//点击前
//点击后
你可以监听状态:
//语音是否关闭mCb_Voice.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener(){@OverridepublicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){if(isChecked){//执行关闭语音MGToast.showToast("执行关闭语音");}else{//执行开启语音MGToast.showToast("执行开启语音");}}});
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。