EditText View in Android
EditText is a TextView which is editable. It has almost similar properties as a TextView. EditText is used when you want to have a text field in your application where user can enter any text. It can be either single line or multi-line. Touching a text field places makes the field active, places a cursor and automatically displays the keyboard.
Following are some of the attributes that are most commonly used:
Used to specify what the text entered should be like and for what purpose it will be used. If this is set to
none, then the text cannot be edited. Some commonly used constant values for this attribute are:
- textAutoComplete - This provides with suggestions as user is typing in text.
- textAutoCorrect - This will enable auto correct on user input text.
- textPassword - Display the entered text in form of dots or stars.
- phone - This will present only the numeric keyboard to users.
- datetime, etc.
All the available constant values can be checked here.
We can use more than one constant value, by separating them using
|, for example :
|In most input methods, like keyboard or SMS sending form, the bottom right corner of the keyboard has an action button appropriate for that input method. It can be Done, Next, Send, Go etc. To specify the keyboard action button, use the |
android:imeOptions attribute with an action value such as actionSend or actionSearch etc.
|It provides the view, with a height equivalent to the specified number of lines on the screen. So, if you enter a value |
2, then by default the EditText view will be 2 lines tall, even without any text added to it. It will the the default height.
|It sets the maximum number of lines that the EditText view can accomodate, visually. In other words when we say |
maxLines has a value 3, it means that the EditText view field will be 3 lines tall after which it will stop increasing in size as more and more text is added to it, usually a scroll bar is shown when number of lines exceeds the limit set.
|It displays a hint message before anyone types in the EditText.|
|It allows to specify the maximum number of characters that the user can enter into the field.|
Below is a sample of a default EditText field:
android:hint="Write your email Address here"
android:hint="Write your email address here"
This attribute gives a hint to the user about what should be entered in the box. This is a temporary message that goes off as soon as the user starts to write anything in the field.
This attribute specifies what the text entered should be like and for what purpose it will be used. Here, we have used
textWebEmailAddress that will allow only email inputs.
This displays at max. only 3 lines of text. If your text exceeds more than 3 lines, then the first row of text is shifted up i.e it will not be visible and text from row 2 to row 4 will be visible. Although we should keep the value to be 1 for an email address field, but we set it to 3 just to explain its use here.