Create An Edit Text App In Android Applications Using Android Studio

Introduction

In this blog, you will learn how to create an EditText app, using Android Studio.

Requirements

  • Android Studio 2.1.3

If you want to create an EditText app, follow the steps given below.

Step 1

Now, open Android Studio and you can choose the file. Subsequently, choose New and afterwards, select New Project.

Android Studio

Step 2

Here, you can create your Application name and choose where your project is stored on the location. Now, click Next button.

Android Studio

Now, we can select the version of an Android; it is Target Android Devices.

Android Studio

Step 3

Here, we can add the activity and click Next button.

Android Studio

Now, we can write the activity name and click Finish button.

Android Studio

Step 4

Now, open your project and you will go to activity_main.xml and afterwards, build the design. You should choose the toolbox, if you want some options (edittext, button) and use the drag and drop method.

Android Studio

Step 5

Here, you need to build on the design and write .XML code.

activity_mai.xml code

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="xyz.rvconstructions.www.edittextapp.MainActivity">  
  3.     <EditText android:id="@+id/simpleEditText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="#F2F2F2" android:hint="Enter Your Name Here" android:padding="15dp" android:textColorHint="#000" android:textStyle="bold|italic" android:layout_marginTop="100dp" />  
  4.     <Button android:id="@+id/displayText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#000" android:padding="10dp" android:text="Display Text" android:textColor="#0f0" android:textStyle="bold" /> </RelativeLayout>  
Step 6

Now, you will go to the MainActivity.java page and build Java code.

First of all, you will declare a file that's an extension file.

Android Studio

Now, we can see MainActivity.java code.
  1. package xyz.rvconstructions.www.edittextapp;  
  2. import android.graphics.Color;  
  3. import android.support.v7.app.AppCompatActivity;  
  4. import android.os.Bundle;  
  5. import android.view.Menu;  
  6. import android.view.MenuItem;  
  7. import android.view.View;  
  8. import android.widget.Button;  
  9. import android.widget.EditText;  
  10. import android.widget.Toast;  
  11. public class MainActivity extends AppCompatActivity {  
  12.     @Override  
  13.     protected void onCreate(Bundle savedInstanceState) {  
  14.         super.onCreate(savedInstanceState);  
  15.         setContentView(R.layout.activity_main);  
  16.         final EditText simpleEditText = (EditText) findViewById(R.id.simpleEditText);  
  17.         Button displayText = (Button) findViewById(R.id.displayText);  
  18.         displayText.setOnClickListener(new View.OnClickListener() {  
  19.             @Override  
  20.             public void onClick(View view) {  
  21.                 if (simpleEditText.getText().toString() != null) {  
  22.                     Toast.makeText(getApplicationContext(), simpleEditText.getText().toString(), Toast.LENGTH_LONG).show(); //display the text that you entered in edit text   
  23.                 }  
  24.             }  
  25.         });  
  26.     }  
  27. }  
Step 7

Here, you will go to run it and select Run-> Run app option.

Android Studio

Here, you will choose Emulator or the devices; it is Nokia Nokia _X.

Android Studio

Step 8

Here, you can see the output.

Android Studio

Now, you will write some name and afterwards, you will click the submit button.

Android Studio