第一种:在原生中只调整显示位置等:

<CheckBox
android:id="@+id/checkBox8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null" //这个很重要,必须null
android:drawableBottom="?android:attr/listChoiceIndicatorMultiple" //显示格式以及位置
android:gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_centerVertical="true"
android:text="测试按钮" />

效果:


第二种:直接自定义按钮类型
1、准备两个按钮的图片,表示选中和未选中状态,上传到drawable中,再加入一个格式定义
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/checkbox_select"
android:state_checked="true"/>
<item
android:drawable="@drawable/checkbox_noselect"
android:state_checked="false"/>
<item
android:drawable="@drawable/checkbox_noselect"/>

</selector>



2、再再style中定义对应的格式名称
<style name="checkboxstyle" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_selected</item>
</style>

3、再应用
<CheckBox
android:id="@+id/checkBox8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_centerVertical="true"
style="@style/checkboxstyle"
android:text="测试按钮" />

 
 

 

 

 
posted on 2019-04-25 10:29  FEX-x  阅读(1212)  评论(0编辑  收藏  举报