Android基础控件 - RadioButton与CheckBox

来源:互联网 发布:手机可以plc编程软件吗 编辑:程序博客网 时间:2024/06/05 15:36

一. RadioButton 单选框

(1) orientation 横纵向

(2) 监听是否选中,两种方法:

① setOnCheckedChangedListener,重写onCheckedChanged(radioGroup, int checkid)方法

② 遍历RadioGroup,判断isChecked。相关方法:getChidChout()、getChildAt(index)、isChecked()


二. CheckBox 复选框

(1) setOnCheckedListener监听每个checkbox

(2) 自定义CheckBox

使用selector,分别设置state_checked为true或者false时的图片,注意两种情况state_enabled都要设为true

(3) 改变文字与选项框的相对位置

drawableTop/Right/Left/Bottom

(4) 文字与选修框的距离:paddingLeft/...

0 0
原创粉丝点击