一、简介
-
ToggleButton
常用属性属性 含义 checked 按钮开关状态, boolean
。disabledAlpha 设置按钮在禁用时的透明度 textOff 按钮关闭时显示的文字 textOn 按钮打开时显示的文字 -
Switch
常用属性属性 含义 checked 按钮开关状态, boolean
。disabledAlpha 设置按钮在禁用时的透明度 textOff 按钮关闭时显示的文字 textOn 按钮打开时显示的文字 textStyle 文字风格、粗体、斜体、下划线… showText 设置开/关的时候是否显示文字, boolean
。splitTrack 是否设置一个间隙,让滑块与底部图片分割, boolean
。switchMinWidth 设置开关的最小宽度 switchPadding 设置滑块内文字的间隔 switchTextAppearance 设置开/关文字外观 track 底部图片,通过 drawable
配置selector
。thumb 滑块图片,通过 drawable
配置selector
。typeface 设置字体,默认支持这三种: sans
、serif
、monospace
,此以外还可以使用其他字体文件(*.ttf
)
二、使用
-
代码
<ToggleButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:textOff="关" android:textOn="开"/> <Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:showText="true"/>
-
效果