Preface
Keywords: Android API Chinese, Android Chinese API, Android SDK Chinese
This chapter translates Android. widget. togglebutton into a switch button. More friends are welcome to join the Chinese translation operation of Android Api! Thanks again for the point support provided by the mobile community! My mailbox over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog: http://www.cnblogs.com
Farmer's uncle: http://www.cnblogs.com/over140/
Version
Android 2.2 r1
Body
I. Structure
Public class togglebutton extends compoundbutton
Java. Lang. Object
Android. View. View
Android. widget. textview
Android. widget. Button
Android. widget. compoundbutton
Android. widget. togglebutton
Ii. Category Overview
Use a button with the brightness indicator and the default text is "on" or "Off" to display the selected/unselected status.
Iii. xml attributes
Attribute name |
Description |
Android: disabledalpha |
Set the transparency when the button is disabled. |
Android: textoff |
Text of the button that is not selected |
Android: texton |
Text of the selected button |
Iv. Public Methods
Public charsequence gettextoff ()
Returns the text that is not selected.
Return Value
Text
Public charsequence gettexton ()
Return the text selected by the button.
Return Value
Text
Public void setbackgrounddrawable (drawable D)
Set the specified printable image as the background or delete the background. If the background has a margin, the margin of this view is the margin of the background. However, when the background is deleted, the margin of the view cannot be touched. To set margins, use setpadding (INT, Int, Int, INT ).
(Note: If you delete a background, it will not be displayed. In addition, the selected and selected images will not be displayed after the background is set, for example, implementation code:
)
Parameters
D. Set the printable image as the background, or set it to empty to delete the background.
Public void setchecked (Boolean checked)
Change the selected status of the button.
Parameters
Checked true: select the button; false: deselect the button.
Public void settextoff (charsequence textoff)
Text displayed when the setting button is not selected.
Parameters
Textoff text
Public void settexton (charsequence texton)
Set the text displayed when the button is selected.
Parameters
Texton text
5. Protected Methods
Protected void drawablestatechanged ()
This method is called when the view status changes and the displayed printable status is affected.
Make sure that the parent class method is called during overwriting (Translator's note: Super. drawablestatechanged ()).
Protected void onfinishinflate ()
Called when the XML file loads the view. This function is called at the final stage of loading, and all child views have been added.
Even if the subclass overrides the onfinishinflate method, always make sure to call the parent class method (Note: Super. onfinishinflate () so that the system can call it.
6. Download
Http://download.csdn.net/source/2746654
8. Series
Android 2.2 API Chinese Document Series (1) -- textview
Android 2.2 API Chinese Document Series (2) -- edittext
Android 2.2 API Chinese Document Series (3) -- accessibilityservice
Android 2.2 API Chinese Document Series (4) -- manifest
Android 2.2 API Chinese Document Series (5) -- View
Android 2.2 API Chinese Document Series (6) -- imageview
Android 2.2 API Chinese Document Series (7) -- imagebutton
Android 2.2 API Chinese Document Series (8) -- quickcontactbadge
Android 2.2 API Chinese Document Series (9) -- zoombutton
Android 2.2 R1 API Chinese Document Series (10) -- checkbox
Android 2.2 R1 API Chinese Document Series (11) -- radiobutton
Android 2.2 R1 API Chinese Document Series (12) -- button
End
So far, the translation group has been expanded to seven people. Thanks to their enthusiastic participation, we look forward to the early arrival of one or more translations every day.