Android UI components-textview and its sub-classes (5) digitalclock, analogclock, radiobutton, checkbox, togglebutton Summary

Source: Internet
Author: User

Two clock classes: digitalclock and analogclock

You can set the background image for digitalclock, and customize the hour-hour, second-hand, and minute-hand styles.

Example:

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: gravity = "center_horizontal"> <! -- Define a simulated clock --> <analogclock Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> <! -- Define a digital clock --> <digitalclockandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: textsize = "14pt" Android: textcolor = "# f0f" Android: drawableright = "@ drawable/ic_launcher"/> <! -- Define the analog clock and use the custom dial and hour-hand image --> <analogclock Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: dial = "@ drawable/watch" Android: hand_minute = "@ drawable/hand"/> </linearlayout>

Running result:

Radiogroup radio group.

Oncheckedchangelistener () listens to single-choice buttons and clicks events

Note: the IDs of radiobutton and radiogroup cannot be the same.

Togglebutton

Common attributes:

Android: Text of the button when textoff is not selected

Android: Text of the button selected by texton

Android: checked = "true" this status is used to set the initial status. True indicates that the status is on, and false indicates that the status is off. If this status is not set, the default value is off Android: background = "@ drawable/toggleselector" if you want to change the togglebutton enable and disable images, you need to set this attribute. toggleselector will be placed below, which is a selector configuration file listening event: compoundbutton. oncheckedchangelistener ()

Important: setting text spacing in XML is sometimes difficult to control. In this case, you can write the text in the image and set both texton and textoff to "" in XML.

Instance:

Package COM. light. study. android; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. checkbox; import android. widget. radiogroup; import android. widget. toast; public class mainactivity extends activity {private radiogroup gender; private checkbox padding Ming, reading, basketball; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); Init (); initlistener ();} private void Init () {gender = (radiogroup) findviewbyid (R. id. myradiogroup); Specify Ming = (checkbox) findviewbyid (R. id. padding Ming); reading = (checkbox) findviewbyid (R. id. reading); basketball = (checkbox) findviewbyid (R. id. basketball);} private void initlistener () {gender. setoncheckedchangelistener (New radiogroup. oncheckedchangelistener () {@ overridepublic void oncheckedchanged (radiogroup group, int checkedid) {If (checkedid = R. id. female) {toast. maketext (mainactivity. this, "Gender: female", toast. length_long ). show ();} else if (checkedid = R. id. male) {toast. maketext (mainactivity. this, "Gender: male", toast. length_long ). show () ;}}); Specify Ming. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {toast. maketext (mainactivity. this, "Hobbies: Swimming", toast. length_long ). show () ;}}); reading. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {toast. maketext (mainactivity. this, "Hobbies: reading", toast. length_long ). show () ;}}); basketball. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {toast. maketext (mainactivity. this, "Hobbies: Basketball", toast. length_long ). show ();}});}}

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: gravity = "center_horizontal" Android: orientation = "vertical"> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: Orientation = "horizontal"> <textview Android: layout_width = "wrap_content" Android: layout_height = "Wrap_content" Android: text = "Gender:"/> <! -- Create a radiogroup --> <radiogroup Android: Id = "@ + ID/myradiogroup" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: orientation = "horizontal"> <! -- The First radiobutton --> <radiobutton Android: Id = "@ + ID/female" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "female"/> <! -- The second radiobutton --> <radiobutton Android: Id = "@ + ID/Male" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "male"/> </radiogroup> </linearlayout> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: orientation = "horizontal"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Hobbies:"/> <checkbox Android: id = "@ + ID/swimming" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "swimming"/> <checkbox Android: id = "@ + ID/basketball" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "basketball"/> <checkbox Android: id = "@ + ID/reading" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "read"/> </linearlayout>

:


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.