How to insert an email in android application in android version 8

Email Address Insertion

It is used to insert email adrress from the user in the android application.The only point of difference between an EditText and an Emailtext is that EmailText consisits of attribute named as android:inputType="textEmailAddress".

Email address consists of a local part followed by '@' and then a case sensitive domain name.

In this tutorial, we are going to demonstrate the use of Email Edit text.

Step 1: Create a brand new android project on android studio IDE.

/></figure>
<!-- /wp:image -->


<!-- wp:list -->
<ul><li>Open the android studio</li><li>Select create a new project</li><li>Insert your application name, company domain(if any) and the location of the project press on next and then finish.</li></ul>
<!-- /wp:list -->


<!-- wp:paragraph -->
<p><strong>Step 2:</strong> After creating the new android studio project, you will be displayed XML file and a java file corresponding to it.</p>
<!-- /wp:paragraph -->


<!-- wp:paragraph -->
<p><strong>Step 3:</strong></p>
<!-- /wp:paragraph -->


<!-- wp:image {

In the next step, select the activity_main.xml file to access the front-end side of the android application.

Step 4: Go to the design tab and select email under text.

Step 5: Drag and drop email on your android application preview.

After getting the email edit text XML file will look like this:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
    android:id="@+id/layout">


    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="173dp"
        android:ems="10"
        android:inputType="textEmailAddress" />
</RelativeLayout>

android:inputType="textEmailAddress"

This line represents an Edit text as an textEmailAdress i.e. this Edit Text will be used to insert email from the user.

After the step 5, front-end work is completed, you can take a button for 'submit' according to your requirement. You can also go through my android Button tutorial to understand the working of button in android application.

Step 6: Insert the following code in your Main Activity file:

import android.widget.EditText;

Step 7: Insert the following code in your MainActivity class:

private EditText email;

This will create an instance variable of class EditText as email.

Step 8: Inside the onCreate method of your MainActivity class, insert the following code:

email=findViewById(R.id.editText);
String mail=email.getText().toString();

This will initialize the email instance.

Step 9: In the final step, you can use the String mail to get the email inserted by the user.

Developer may check the email-address entered by the user against the email in his database via mail String.

I would suggest you to take a button to insert the email from the user.

Insert the following code on your onCreate method inside the

MainActivity.java file:

if(mail==HR@javatpoint.com){
Toast.makeText(MainActivity.this,"Welcome HR@javatpoint.com",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this,"Not a valid user",Toast.LENGTH_SHORT).show();
}

Related Topics

Android Date picker example

How to pick date from the user in Android? Write an android example to pick date from the user and display it. Android provides control for the user to pick a date...

3 minutes read.

Android Activity

What is an Activity? Android Activity is a screen in the user interface of an Android application. In this way, Android activity is very similar to the desktop application window. An...

4 minutes read.

What is Android Studio

Android Studio powered by the IntelliJ platform is an integrated development environment (IDE) and is officially recognized for developing androidapplications. Its foundation lies on JetBrains' IntelliJ IDEA and is specialized...

3 minutes read.

Android RecyclerView

RecyclerView is a ViewGroup brought to AndroidStudio as successor to ListView and GridView. These are all improvements and are included in the latest v7 support package. It was written to...

8 minutes read.

Android Time picker example

How to pick Time from the user in android? Write an android example to pick Time from the user and display the date to the user. Android provides controls for the user...

3 minutes read.

Difference between android developer and web

From a small business to a big firm, every organization in the world of technology requires a digital market presence and only mobile applications and websites/web applications provide for digital...

4 minutes read.

Android Studio Resources

To build an outstanding Android application there are many items that you need to use. Aside from the coding of your application, you need to handle various resources such as...

5 minutes read.

Android Navigation Drawer

A sliding menu used to show important links in the Android Application is called Navigation Drawer. The navigation drawermakes it easier to navigate between the fragments. It is not displayed...

5 minutes read.

How to crop Image from Camera and Gallery in Android?

In this tutorial, we'll learn how to crop photos in the Android Gallery and Camera. There is no crop feature in this project, contrary to what was covered in the...

5 minutes read.

Assets folder in Android

You might have noticed that unlike the Eclipse ADT (App Development Tools), the Android Studio does not have an Assets folder, which is mainly used to store the web resources...

3 minutes read.

Creating a Calendar View App in Android

This article demonstrates how to make an Android application that uses CalendarView to display the Calendar. It also provides the option to pick the current date and view the date....

3 minutes read.

Android TextView

Widgets are user interface (UI) elements that help users to interact with Android applications. It is one of many equipments that can be used to improvise the user interface of...

4 minutes read.

Android Tutorial

This Android tutorial will provide you with all the concepts that will be beneficial for both beginners and advanced-level students or candidates. You can learn this tutorial to begin your...

6 minutes read.

Android Studio's Layout Editor

The Layout Editor allows you to efficiently create layouts by dragging UI elements from the Palette into the visual design editor instead of manually creating the layout XML file by...

8 minutes read.

Android Styles and Themes

Android styles allow you to design the appearance (for example, colors, size, and fonts) of Android UI components from XML resource files. With this method, you only need to set...

5 minutes read.

How to Generate QRCode in Android?

Many apps use QR codes to show data in a way that is machine-readable. Data is represented using these codes in a secure manner such that only computers, not humans,...

4 minutes read.

AdapterViewFlipper in Android with Example

The AdapterViewFlipper class, a subclass of the ViewAnimator class, is what we use to switch from two or multiple views when only one is present at a time. The AdapterViewFlipper...

10 minutes read.

Jetpack Architecture Components in Android

A collection of software elements, libraries, tools, and instructions is called Android Jetpack. It is available to assist in creating reliable Android applications. Jetpack, which was introduced by Google in...

8 minutes read.

How to reduce the size of APK in Android

What exactly is an APK file? The full form of APK is Android Package Kit. It is the Android operating system's application file format. We use Android Studio to generate APK...

7 minutes read.

Android Emulator

A tool for creating Android virtual devices (including software and virtual hardware) on your personal desktop is known as Emulator. We can use these virtual devices as the target device...

4 minutes read.