您的位置:首页 > 移动开发 > Android开发

Android之自定义checkbox并解决内容和复选框之间的具体问题

2018-01-30 21:12 549 查看

1、问题

checkbox自定义并解决内容和复选框之间的具体问题

2、代码实现

1、select_checkbox.xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/check_press5" android:state_checked="true"/>
<item android:drawable="@drawable/check_normal5" android:state_checked="false"/>
<item android:drawable="@drawable/check_normal5" />
</selector>

2、在styles.xml里面自定义样式
<style name="checkboxstyle" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/selector_checkbox</item>
<item name="android:padding">10.0dip</item>
></style>注意这里的android:padding熟悉就可以把自定义图片和文字内容隔开了

3、一左一右使用

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="1dp"
>
<CheckBox
android:id="@+id/man"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="man"
style="@style/checkboxstyle"
/>
<CheckBox
android:id="@+id/woman"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="1dp"
android:text="woman"
style="@style/checkboxstyle"
/>
</RelativeLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: