Android learning notes-EditText (input box) (1), android-edittext
Reference: http://www.runoob.com/w3cnote/android-tutorial-edittext.html
1. Set the default prompt text
The two attributes of the prompt text are as follows by default:
Android: hint = "default prompt text" android: textColorHint = "# 95A1AA"
The former sets the text content of the prompt, and the latter sets the color of the prompt text!
2. Select all text content in the component after obtaining the focus
When we click to get the focus in the input box, we do not move the cursor to the beginning or end of the text; instead, we get all the text in the input box! In this case, we can useSelectAllOnFocusAttribute
android:selectAllOnFocus="true"
For example, the first one sets this attribute, and the second one does not set this attribute. The EditText set to true gets the focus and selects all the texts!
3. Restrict the EditText input type
Sometimes we may need to restrict the input data. For example, when you enter a phone number, you enter a letter. This is obviously not what we expected, the inputType attribute can be used to restrict the input type!
For example, only the phone number and password (TextPassword):
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="phone" />
There are other optional parameters, see the original link.
4. Set the minimum line, maximum line, single line, multiple lines, and automatic line feed.
EditText is displayed in multiple rows by default and can be automatically wrapped. That is, when one row cannot be displayed, it is automatically switched to the second line.
We can restrict it, for example
Set the minimum number of rows:Android: minLines = "3"
Or set the maximum number of lines in EditText:Android: maxLines = "3"
PS: when the input content exceeds maxline, the text will automatically scroll up !!
In addition, in many cases, we may want to restrict EditText to only allow single-line input without scrolling. For example, in the above login interface Example, we only need to set
android:singleLine="true"
You can achieve single-line input without line breaks
5. Set the text interval and uppercase letters
We can use the following two attributes to set the word Spacing:
Android: textScaleX = "1.5" // sets the horizontal interval between words. android: textScaleY = "1.5" // sets the vertical interval between words and words.
In addition, EditText also provides the attributes for setting uppercase letters:Android: capitalizeThe default value is none. Three Optional values are provided:
- Sentences:Only the first letter is capitalized.
- Words:The size of the first letter of each word. Separate words with spaces.
- Characters:Each letter is capitalized.