Android EditText Control

Android EditText Control

An EditText control can be defined as an overlay over the TextView control. It is configured in such a way that the EditText field can be edited. In fact, it is a subclass of the TextView base class but it possesses rich editing properties.

Also Read: Android TextView Control

List of EditText Attributes
In the below-provided table, we have listed out the major attributes of the EditText control but in case, you want to view the complete list of EditText attributes then check out the official Android document. You will also get to see all the associated methods which will provide you the ability to change the value of any of these attributes at the runtime.


The below-given list of attributes is inherited from the android.widget.TextView class.

S.No. Attribute Description
1 android:autoText * This attribute sets the field to be capable of accepting textual input. It also automatically corrects a few common spelling mistakes.
2 android:drawableBottom * This attribute supports a drawable value. This value appears below the text.
3 android:drawableRight * This attribute accepts a drawable value which appears to the right of the displayed text.
4 android:editable * This attribute sets the EditText to be capable of accepting an input value.
5 android:text * The text passed to this attribute is displayed on the screen.

The below given list of attributes is inherited from the android.view.View class.

S.No. Attribute Description
1 android:background * This attribute accepts the drawable value which is to be used as the background.
2 android:contentDescription * This attribute provides a brief description of the view’s content.
3 android:id * This attribute sets a unique id for the view.
4 android:onClick * If set, this attribute is used to invoke the view whenever the UI control is clicked.
5 android:visibility * This attribute sets the visibility or invisibility of the view.



The following example will help you to understand the creation of an Android application with the help of the Linear layout and EditText control.

Step 1: Start with the creation of an Android application on the Android Studio IDE. Save this newly created application as demo. Place it under the com.example.demo package as already explained in the Hello World Example chapter.

Step 2: Modify the main activity file, which is You can locate this file under the src/com.example.demo/ path. In this file, you need to add a click event along with the already existing fundamental lifecycle callback methods.

package com.example.demo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity
   EditText eText;
   Button btn;

   protected void onCreate(Bundle savedInstanceState)
      eText = (EditText) findViewById(;
      btn = (Button) findViewById(;
      btn.setOnClickListener(new OnClickListener()
         public void onClick(View v)
            String str = eText.getText().toString();
            Toast msg = Toast.makeText(getBaseContext(),str,Toast.LENGTH_LONG);

Step 3: Modify activity_main.xml file. You can easily find this file by tracing the res/layout/ directory. In this file, you are required to include Android UI control.

<RelativeLayout xmlns:android=””
   tools:context=”.MainActivity” >

      android:text=”@string/example_edittext” />

      android:text=”@string/show_the_text” />      

      android:text=”@string/enter_text” android:inputType=”text” />


Step 4: In strings.xml, you need to define the new string constants to be used. You can find this file under the res/values/ path. 

<?xml version=”1.0″ encoding=”utf-8″?>
   <string name=”app_name”>demo</string>
   <string name=”example_edittext”>Example showing EditText</string>
   <string name=”show_the_text”>Show the Text</string>
   <string name=”enter_text”>text changes</string>

Step 5: Make sure that the AndroidManifest.xml file remains as it is. The default content of this file is given below.

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=””
   package=”com.example.demo” >      
      android:theme=”@style/AppTheme” > 

         android:label=”@string/app_name” >      
            <action android:name=”android.intent.action.MAIN” />
            <category android:name=”android.intent.category.LAUNCHER” />

Step 6: The final step is to run your demo application. For this, we are assuming that you have already created AVD during the environment setup. Open any of your project’s activity files. Now, locate the Run button from the toolbar. Click on it and the Studio will initiate the installation of your demo application on the AVD. If the setup and the application fall in right place then the Emulator window will display the final output of your Android application.