Saturday, November 2, 2019

Android EditText Example

Introduction to this Android EditText Example:
In the previous section, we learned the first UI control TextView (text box), which gives a lot of solutions to some of the requirements that may be encountered in actual development, which should bring convenience to your development, in this section. Let's learn the second very common control EditText (input box); very similar to TextView, the biggest difference is: EditText can accept user input! As before, we don't talk about properties one by one, change EditText font Android just about the actual application. To deduct the properties, you can view the API documentation yourself: API documentation; then start this section!
1. Set the default prompt text
As shown below, I believe that you are no stranger to this user login interface, yes, we use this interface many times.
Compared to the other, what about the following?
Not bad, of course, will not paste the layout here, here only introduce two control attributes of the default prompt text:
Android EditText Example

The two properties of the default prompt text are as follows:
android:hint="Default prompt text"
android:textColorHint="#95A1AA"
2. Select all the text content in the selected component after getting the focus
When we want to get the focus after clicking the input box, instead of moving the cursor to the beginning or end of the text; instead, get all the text content in the input box! At this time we can use the selectAllOnFocus property.
Android:selectAllOnFocus="true"
For example, the following renderings: The first is to set the property, the second is not set the property, the convert EditText text to all uppercase in Android set to true after the focus is selected all the text!
3. Limit the EditText input type
Sometimes we may need to limit the input data, such as when you enter a phone number, you enter a string of letters, which obviously does not meet our expectations, and the limit input type can be achieved through the inputType attribute!
For example, the limit can only be the phone number, password (textPassword):
<EditText 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:inputType="phone" />  
The optional parameters are as follows:
Text type, mostly uppercase, lowercase, and numeric symbols
android:inputType="none" 
android:inputType="text" 
android:inputType="textCapCharacters" 
android:inputType="textCapWords" 
android:inputType="textCapSentences" 
android:inputType="textAutoCorrect" 
android:inputType="textAutoComplete" 
android:inputType="textMultiLine" 
android:inputType="textImeMultiLine" 
android:inputType="textNoSuggestions" 
android:inputType="textUri" 
android:inputType="textEmailAddress" 
android:inputType="textEmailSubject" 
android:inputType="textShortMessage" 
android:inputType="textLongMessage" 
android:inputType="textPersonName" 
android:inputType="textPostalAddress" 
android:inputType="textPassword" 
android:inputType="textVisiblePassword" 
android:inputType="textWebEditText" 
android:inputType="textFilter"
android:inputType="textPhonetic"  
EditText Numerical type
android:inputType="number" 
android:inputType="numberSigned" 
android:inputType="numberDecimal" 
android:inputType="phone"
android:inputType="datetime" 
android:inputType="date"
android:inputType="time" 
4. Set the minimum line, maximum line, single line, multiple lines, automatic line break
EditText is multi-line by default, and can automatically wrap, that is, when a line is not displayed, he will automatically switch to the second line.
android:singleLine="true"
 5. Set the text interval, set the English letter uppercase type
We can set the spacing of words by the following two properties:
android:textScaleX="1.5"
android:textScaleY="1.5"
6. Control the separation distance around the EditText and the distance between the internal text and the border
7. Set EditText to get the focus, while popping up the keypad

No comments:

Post a Comment