您的位置:首页 > 其它

状态开关按钮(ToggleButton)和开关(Switch)的功能与用法

2015-11-26 16:04 555 查看
状态开关按钮(ToggleButton)和开关(Switch)是由Button派生出来的,因此他们的本质也是按钮,Button支持的各种属性、方法也适用于ToggleButton和Switch。从功能上来看,ToggleButton、Switch与CheckBox复选框非常相似,他们都可以提供两种状态。不过ToggleButton、Switch与CheckBox的区别主要体现在功能上,ToggleButton、Switch通常用于切换程序中的某种状态。

1、ToggleButton支持的xml属性及相关方法
xml属性相关方法说明
android:checkedsetChecked(boolean)设置该按钮是否被选中
android:textOff 设置当该按钮的状态关闭时显示的文本
android:textOn 设置当该按钮的状态打开时显示的文本
2、Switch支持的xml属性及相关方法
xml属性相关方法说明
android:checkedsetChecked(boolean)设置该开关是否被选中
android:switchMinWidthsetSwitchMinWidth(int)设置该开关最小的宽度
android:switchPaddingsetSwitchPadding(int)设置开关与标题文本之间的空白
android:switchTextAppearancesetSwitchTextAppearance(Context,int)设置该开关图标上的文本样式
android:textOffsetTextOFff(CharSequence)设置该开关的状态关闭时显示的文本
android:textOnsetTextOn(CharSequence)设置该开关的状态打开时显示的文本
android:textStylesetSwitchTypeface(Typeface)设置该开关的文本风格
android:thumbsetThumbResource(int)指定使用自定义Drawable绘制该开关的开关按钮
android:tracksetTrackResource(int)指定使用自定义Drawable绘制该开关的开关轨道
android:typefacesetSwitchTypeface(Typeface)设置该开关的文本的字体风格
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  checkbox switch xml