How To Create A Simple Login Form In Android Studio Through Email And Password

Hello Guys,
Today i am going to show you how to create a simple login form in android studio where user have to enter their email and password, if email and password will be correct it will generate "Login Successful" message else it will generate "Enter valid details" if email and password will be incorrect. So Lets begin with the Java code which is used in android studio to make the application.

We have divided the whole coding into two parts in which first is for designing the application and second is for all links and condition means java coding.


activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E3E7FB"
    tools:context=".MainActivity">

    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:src="@drawable/rubex"
        android:scaleType="fitCenter"
        android:background="#E3E7FB"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="UNoWorld"
        android:textAlignment="center"
        android:textStyle="bold"
        android:textSize="50dp"
        android:textColor="#581845"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="----------------------------------"
        android:textAlignment="center"
        android:textSize="30dp"
        />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Email ID"
        android:id="@+id/email"
        android:inputType="text"
        />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Password"
        android:id="@+id/password"
        android:inputType="textPassword"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LogIn"
        android:id="@+id/btn"
        android:layout_marginVertical="5dp"
        android:layout_marginHorizontal="150dp"
        />

</LinearLayout>

Mainactivity.java

package com.myhindiadvice.www.loginpage;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        OnCLick();
    }

    EditText email,password;
    Button btn;

    public void OnCLick()
    {
        email=(EditText)findViewById(R.id.email);
        password=(EditText)findViewById(R.id.password);
        btn=(Button)findViewById(R.id.btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            if (email.getText().toString().equals("abc@gmail.com") && password.getText().toString().equals("654321"))
            {
                Toast.makeText(MainActivity.this, "LogIn Succesful", Toast.LENGTH_LONG).show();
            }else
            {
                Toast.makeText(MainActivity.this, "Enter Valid Detials", Toast.LENGTH_SHORT).show();
            }

            }
        });
    }
}

Here after the whole coding its time to check output of our application. so i have checked the output, everything is working correctly.

Hope this was helpful for you. if you are facing any problem or issue just comment below, we will reply you as soon as possible.
Thanks For Your Time.


Latest
Next Post

post written by:

0 comments: