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
All the available constant values can be checked here.
We can use more than one constant value, by separating them using
|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 |
|It provides the view, with a height equivalent to the specified number of lines on the screen. So, if you enter a value |
|It sets the maximum number of lines that the EditText view can accomodate, visually. In other words when we say |
|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:
<EditText android:id="@+id/et_address" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Write your email Address here" android:textSize="20sp" android:inputType="textWebEmailAddress" android:imeOptions="actionDone" android:maxLines="3"/>
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.