- android
- android.accessibilityservice
- android.accounts
- android.content
- android.database.sqlite
- android.graphics
- android.location
- android.media
- android.net
- android.os
- android.text
- android.view
- android.view.inputmethod
- android.widget
- AbsListView
- AbsoluteLayout
- AbsSeekBar
- AbsSpinner
- AdapterView
- AnalogClock
- BaseAdapter
- BaseExpandableListAdapter
- Button
- CheckBox
- CheckedTextView
- Checkable
- Chronometer
- CompoundButton
- CursorAdapter
- CursorTreeAdapter
- DatePicker
- DialerFilter
- DigitalClock
- EditText
- Filter
- Filter.FilterListener
- Filter.FilterResults
- ExpandableListAdapter
- Filterable
- Gallery
- Gallery.LayoutParams
- GridView
- GridLayout
- RadioGroup
- ImageView
- HorizontalScrollView
- ImageButton
- ImageSwitcher
- FilterQueryProvider
- ListAdapter
- ListView
- MediaController
- QuickContactBadge
- RadioButton
- RatingBar
- RelativeLayout
- RemoteViews
- ResourceCursorAdapter
- ResourceCursorTreeAdapter
- Scroller
- ScrollView
- SearchView
- SeekBar
- SeekBar.OnSeekBarChangeListener
- SimpleAdapter
- SimpleCursorAdapter
- SimpleCursorTreeAdapter
- SimpleExpandableListAdapter
- SlidingDrawer
- Spinner
- SpinnerAdapter
- WrapperListAdapter
- TabHost
- TabHost.TabSpec
- TextView
- TimePicker
- Toast
- TableLayout
- TableRow
- TableRow.LayoutParams
- TabWidget
- TextSwitcher
- ToggleButton
- TwoLineListItem
- VideoView
- ViewAnimator
- ViewFlipper
- ViewSwitcher
- ZoomButtonsController
- ZoomButton
- ZoomControls
- dalvik.system
ToggleButton
ToggleButton
农民伯伯
版本:Android 2.2 r1
public class ToggleButton extends CompoundButton
java.lang.Object
android.widget.CompoundButton
android.widget.ToggleButton
概述
通过一个带有亮度指示同时默认文本为“ON”或“OFF”的按钮显示选中/未选中状态。
XML 属性
属性名称 | 描述 |
android:disabledAlpha | 设置按钮在禁用时透明度。 |
android:textOff | 未选中时按钮的文本 |
android:textOn | 选中时按钮的文本 |
公共方法
public CharSequence getTextOff ()
返回按钮未选中时的文本。
返回值
文本
public CharSequence getTextOn ()
返回按钮选中时的文本。
返回值
文本
public void setBackgroundDrawable (Drawable d)
设置指定的可绘制(译者注:如图片)为背景,或删除背景。如果让背景有边距,这个视图的边距就是背景的边距。然而,当背景被删除时,这个视图的边距不能被触摸。如果需要设置边距,请使用方法 setPadding(int, int, int, int)。
(译者注:如果设置删除背景整个就不显示了,此外设置背景后选中和被选中的图片也不显示了,如下图:,实现代码:
)
参数
d 设置可绘制(译者注:如图片)为背景,或设置为空删除背景。
public void setChecked (boolean checked)
改变按钮的选中状态。
参数
checked true 让按钮选中,false 让按钮不选中
public void setTextOff (CharSequence textOff)
设置按钮未选中时显示的文本。
参数
textOff 文本
public void setTextOn (CharSequence textOn)
设置按钮选中时显示的文本。
参数
textOn 文本
受保护方法
protected void drawableStateChanged ()
在视图状态的变化影响到所显示可绘制的状态时调用这个方法。
确保在覆盖时中调用父类方法(译者注:super. drawableStateChanged ())。
protected void onFinishInflate ()
XML 文件加载视图完成时调用。这个函数在加载的最后阶段被调用,所有的子视图已经被添加。
即使子类重写了 onFinishInflate 方法,也应该始终确保调用父类方法(译者注:super. onFinishInflate()),使系统能够调用。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论