XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attribute Name
|
Related Method
|
Description
| |||||||||
android:switchMinWidth | setSwitchMinWidth(int) | Minimum width for the switch component Must be a dimension value, which is a floating point number appended with a unit such as " | |||||||||
android:switchPadding | setSwitchPadding(int) | Minimum space between the switch and caption text Must be a dimension value, which is a floating point number appended with a unit such as " | |||||||||
android:switchTextAppearance | setSwitchTextAppearance(Context,int) | TextAppearance style for text displayed on the switch thumb. | |||||||||
android:textOff | setTextOff(CharSequence) | Text to use when the switch is in the unchecked/"off" state. | |||||||||
android:textOn | setTextOn(CharSequence) | Text to use when the switch is in the checked/"on" state. | |||||||||
android:textStyle | setSwitchTypeface(Typeface) | Style (bold, italic, bolditalic) for the text. | |||||||||
android:thumb | setThumbResource(int) | Drawable to use as the "thumb" that switches back and forth. | |||||||||
android:thumbTextPadding | setThumbTextPadding(int) | Amount of padding on either side of text within the switch thumb. | |||||||||
android:track | setTrackResource(int) | Drawable to use as the "track" that the switch thumb slides within. | |||||||||
android:typeface | setSwitchTypeface(Typeface) | Typeface (normal, sans, serif, monospace) for the text. |
以上是switch的方法,switch是Android4.0中的新控件,用来滑动选择开关和
ToggleButton类似;
- android:switchMinWidth:百度翻译--》开关元件的最小宽度必须是一个维度的价值,这是一个浮点数附有单位如“14.5sp”。
- android:switchPadding:文字和控件之间的距离。
- android:switchTextAppearance:使用指定的资源id设置状态标签上的文字大小,类型,颜色等;
- android:textOff、android:textOn:设置开关显示的文字。
- android:textStyle:设置text文字样式:有三种属性,分别是无、加粗、斜体。(中文字体也能加粗)
- android:thumb:设置滑动控件图片。可以使用selector样式来改变开关时候不同的图片。
- android:thumbTextPadding:设置thumb中的文字的两边距离从而达到控制switch的宽度效果。(和android:switchMinWidth属性有点像。但是前者不会改变拖动的图片长度,后者会)
- android:track:设置背景图片可以通过上一个属性来控制背景长度。
- android:typeface:设置文字的属性,有兴趣自己试试,我感觉没什么用。