EditText View in Android
EditText is a TextView which is editable. It has very similar properties as a TextView. EditText is used whenever you want to have a text field in your application where user can fill any text. It can be either single line or multi-line based on the need.
Touching a text field makes the field active, places a cursor and automatically displays the keyboard there.
|android:inputType||Used for specifying whatever the text entered should be like and for what purpose it will be used for. If this is set to none, then the text cannot be edited. Here are some commonly used constant values for this attribute are:
● textAutoComplete – This provides suggestions as user is typing in text.
● textAutoCorrect – This can enable auto correct on user input text.
● textEmailAddressit takes email
● phone – This will take only the numeric keyboard to users.
● datetime,it takes date time .
All are available constant can be checked here.
We can use more than one constant and by separating them using |, for example :
|android:imeOptions||In most input methods are same way keyboard/SMS sending form, the bottom right corner of the keyboard has an action button suitable for that input method and It can be Done, Next, Send, for specifying the keyboard action/operation button, use the android:imeOptions attribute with an action value just as actionSearch etc.|
|android:minLines||It provides a view, and a height equivalent to the provided number of lines on the screen and if you enter a value as 4, then by default the EditText view will be 2 lines tall, as you provided value 2, even without any text added to it. It will be the default height.|
|android:maxLines||It sets maximum number of lines that the EditText view can accommodate, visually and 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 can stop increasing in size as more and more text is added to it and usually a scroll bar is shown when the number of lines exceeds the limit set.|
|android:hint||It displays and show hint message before anyone types in the EditText.|
|android:maxLength||It can specify the maximum 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”
This attribute show hint to the user about what should be entered in the box. This can be 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 and we can use textWebEmailAddress that will allow only email inputs.
This can displays at max. only 2 lines of text. If text exceeds more than 2 lines, then first row of text is shifted up i.e it will not be visible and text from row 2 to row 5 will be visible.