按钮button,继承自textview,是一个可供单击的按钮,单击会触发一个onclick事件,具体事件监听的后面再说。
单选按钮radiobutton和复选框checkbox都继承自button,其用途就像其名字说的。
radiobutton需要和radiogroup一起使用,用于定义一组单选钮。
状态开关按钮togglebutton和开关switch也是继承自button,它们都提供两种状态,通常用于切换程序中的某种状态。
togglebutton支持的xml属性和相关方法
xml属性
相关方法
说明
android:checked
setchecked(boolean)
设置该按钮是否被选中
android:textoff
设置状态关闭时显示的文本
android:texton
设置状态开启时显示的文本
switch支持的xml属性和相关方法
android:switchminwidth
setswitchminwidth(int)
设置开关的最小宽度
android:switchpadding
setswitchpadding(int)
设置开关与标题文本之间的空白
android:switchtextappearance
setswitchtextappearance(context,int)
设置开关图标上的文本样式
settextoff(charsequence)
settexton(charsequence)
android:textstyle
setswitchtypeface(typeface)
设置开关的文本风格
android:thumb
setthumbresource(int)
使用自定义drawable绘制开关按钮
android:thumbtextpadding
setthumbtextpadding(int)
设置按钮与标题文本之间的空白
android:track
settrackresource(int)
使用自定义drawable绘制开关轨道
android:typeface
设置开关文本的字体风格