EditText in Android

Using TextView we are able to display some text. But what happened when user want to add some text in application ? It’s done by EditText in android. EditText allow use to type text into application. EditText is text field which is mostly used in forms. You can add EditText  to your layout using <EditText> element.  EditText is a subclass of TextViewsupplied with text editing operations. In our tutorial we see generally used attributes of EditText.

  • android:id : A unique resource ID for view.
  • android:hint : Hint for user to specify what kind of text to add.
  • android:inputType : Declare what kind of data can entered. Such like text,number,password,email etc.
  • android:singleLine : If true, text appeared in single line else in multi-line.
  • ndroid:ems : Sets the width of a view to fit a text of n ‘M’ letters regardless of the actual text extension and text size.
  • android:textColorHint : Sets Text color of hint text.
  • android:enabled : If true, enable to type text, else just visible, cant write.
  • android:imeOptions : Set action button in virtual keyboard when users have completed their input. Like Done, Go, Next, Send, Search, None etc.
  • android:digits : Only declared characters entered in text field.

This is Basic attributes of EditText. You may find more details on Developer site. Let’s see one example of EditText. Create one Project and add below code into xml file. activity_main.xml


Now Run project. Our output look likes below.

android-edittext-example-1-skynils android-edittext-example-2-skynils android-edittext-example-3-skynils

Download Project.

Now see next tutorial Button Example in Android.

(Visited 831 times, 1 visits today)