[Reading Notes-Android game programming from scratch] 4. system controls commonly used in Android game development (EditText, CheckBox, Radiobutton)

Source: Internet
Author: User

3.4 EditText

EditText official document address:Http://developer.android.com/reference/android/widget/EditText.html

EditText inherits TextView, so EditText has TextView attributes. The following describes the attributes of some EditText-specific input methods.
Android: layout_gravity = "center_vertical": sets the display position of the control: top by default, center, and bottom.
Android: hin: Text indicates the Text prompt information displayed when it is null. You can use textColorHint to set the color of the prompt information.
Android: singleLine: set a single line of input. Once set to true, the text will not wrap automatically.
Android: gray = "top": in multiple rows, the pointer is at the first position of the first row. et. setSelection (et. length ();: Adjust the cursor to the last row.
Android: autoText: Help for automatic spelling. The settings here are ineffective. Other input methods may be required.
Android: capitalize: Set uppercase letters. Set the value as follows: sentences only indicates the size of the first letter of a word in uppercase; words indicates the size of the first letter of a word in uppercase. characters indicates the size of each letter in uppercase.
Android: digits: Specifies the characters that can be entered. For example, "1234567890. +-*/% \ n ()"
Android: singleLine: whether a single line or multiple lines are supported. Press enter to leave the text box or Add a new line android: numeric: If set, the TextView receives the numeric input. It has the following values: integer positive integer, signed integer, and decimal floating point number.
Android: inputType: Set the text type
Android: password. The text is displayed in ".".
Android: phoneNumber: Enter the phone number.
Android: editable: sets whether to edit. The cursor can still be obtained, but cannot be entered.
Android: autoLink = "all": sets the text hyperlink style. When a URL is clicked, it jumps to the URL.
Android: textColor = "# ff8c00": font color
Android: textStyle = "bold": font, bold, italic, bolditalic
Android: textAlign = "center": EditText does not have this attribute, but TextView has
Android: textColorHighlight = "# cccccc": Specifies the background color of the selected text. The default value is blue.
Android: textColorHint = "# ffff00": sets the text color of the prompt message. The default value is gray.
Android: textScaleX = "1.5": controls the spacing between words.
Android: typeface = "monospace": font, normal, sans, serif, monospace
Android: background = "@ null": space background. It is not found here. It indicates transparent.
Android: layout_weight = "1": the weight is useful when the control is displayed.
Android: textAppearance = "? Android: attr/textAppearanceLargeInverse ": Text appearance. Here, it refers to a built-in appearance of the system ,? Indicates whether the system has this appearance. Otherwise, the default appearance is used.

 

                
  MainActivity  EditText et;              ===                 String str =

 

 

3.5 CheckBox

CheckBox official documentation address:Http://developer.android.com/reference/android/widget/CheckBox.html

 

                     
MainActivity Activity cb1 === onCheckedChanged (CompoundButton buttonView, (cb1 = buttonView | cb2 = buttonView | cb3 = toastDisplay (buttonView. getText () + "selected" + "unselected"

 

Modify the CheckBox style:

Add an xml file of the checkbox custom style to res/drawable.

            

Then you can reference it in the layout file.

  

3.6 Radiobutton

 RadiobuttonClass official documentation address:Http://developer.android.com/reference/android/widget/RadioButton.html

The steps for RadioButton and CheckBox listeners are similar. However, you must pay attention to the following three points for RadioButton listeners:
1. RadioButton and CheckBox use different listeners.
2. When RadioButton is bound to a listener, not every RadioButton is bound. Because all RadioButton is placed in the RadioGroup radio group, you only need to bind the listener to the listener.
3. override the listener function onCheckedChanged (RadioGroup group, int checkedId). The first parameter of this function is a single-choice group. Note the second parameter. Here, the checkedId is not the subscript of each RadioButton in the RadioGroup single-choice group, the ID of the RadioButton memory where the status changes. Therefore, when determining which RadioButton has changed its status, you can use RadioButton. getID to compare it with checkedId.

                                     

 

MainActivity Activity ===); onCheckedChanged (RadioGroup group, (group = rg) = (checkedId === (checkedId ==, "select the radio button with the subscript" + rbName +"

 

 

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.