Android Login Signup Form Material Design with Validation

Android Login Signup Form Material Design with Validation – In this article i will show how develop Android Material design layout for Login and Registration user form with validation in Android Studio IDE.. Login and Signup form is very mandatory for every android application so if you are android developer then must know about develop these things in your project.

Without Login and Signup form, no one users are trust your application because user information is not secure. When you have build login form the end user data will be encrypt and store from our database. So its must for each and every android application. If you are a beginner in android don’t worry here i will easily explained for how to make login signup forgot password in Android Studio platform.

When end user forget their email id or password then they are access forgot password option. After that they are reset it, then create new one. Now a days most of persons used this because everyone forgot their password for some other work and there are many social platforms are there so they are forgot which password is will be given for that application.

Android Login Signup Form

Let’s start, As usual first you have to create new project and choose empty activity for start the manual designs. After creating project we have to design UI Login Material Design Layout. So first will implement the Login Activity. Create New activity name is LoginActivity.java and add the following below code,

package com.example.vetbossel.logregform;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class LoginActivity extends AppCompatActivity {
    private ImageView logo, ivSignIn, btnTwitter;
    private AutoCompleteTextView email, password;
    private TextView forgotPass, signUp;
    private Button btnSignIn;
    private FirebaseAuth firebaseAuth;
    private FirebaseUser user;
    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initializeGUI();
        user = firebaseAuth.getCurrentUser();
        if(user != null) {
            finish();
            startActivity(new Intent(LoginActivity.this,MainActivity.class));
        }
        btnSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String inEmail = email.getText().toString();
                String inPassword = password.getText().toString();
                if(validateInput(inEmail, inPassword)){
                    signUser(inEmail, inPassword);
                }
            }
        });
        signUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LoginActivity.this,RegistrationActivity.class));
            }
        });
        forgotPass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LoginActivity.this,PWresetActivity.class));
            }
        });
    }
    public void signUser(String email, String password){
        progressDialog.setMessage("Verificating...");
        progressDialog.show();
        firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() {
            @Override
            public void onComplete(@NonNull Task task) {
                if(task.isSuccessful()){
                    progressDialog.dismiss();
                    Toast.makeText(LoginActivity.this,"Login Successful",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(LoginActivity.this,MainActivity.class));
                }
                else{
                    progressDialog.dismiss();
                    Toast.makeText(LoginActivity.this,"Invalid email or password",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    private void initializeGUI(){
        logo = findViewById(R.id.ivLogLogo);
        ivSignIn = findViewById(R.id.ivSignIn);
        btnTwitter = findViewById(R.id.ivFacebook);
        email = findViewById(R.id.atvEmailLog);
        password = findViewById(R.id.atvPasswordLog);
        forgotPass = findViewById(R.id.tvForgotPass);
        signUp = findViewById(R.id.tvSignIn);
        btnSignIn = findViewById(R.id.btnSignIn);
        progressDialog = new ProgressDialog(this);
        firebaseAuth = FirebaseAuth.getInstance();
    }
    public boolean validateInput(String inemail, String inpassword){
        if(inemail.isEmpty()){
            email.setError("Email field is empty.");
            return false;
        }
        if(inpassword.isEmpty()){
            password.setError("Password is empty.");
            return false;
        }
        return true;
    }
}

Then we have to create one module for forgot password who are forget their password or email to login the account.

Create Forgot Password

Already i say forgot password is very important for every application. So here i have to implement the forgot password option in material design form layout. You have to create new activity and give the name for ForgotpasswordActivity.java and add following below code,

package com.example.vetbossel.logregform;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;

public class PWresetActivity extends AppCompatActivity {
    private ImageView ivLogo,ivPWreset;
    private TextView tvInfo, tvSignin;
    private AutoCompleteTextView atvEmail;
    private Button btnReset;
    private FirebaseAuth firebaseAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pwreset);
        initializeGUI();
        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String email = atvEmail.getText().toString();
                if (email.isEmpty()) {
                    atvEmail.setError("Please, fill the email field.",null);
                }
                else {                  firebaseAuth.sendPasswordResetEmail(email).addOnCompleteListener(new OnCompleteListener() {
                        @Override
                        public void onComplete(@NonNull Task task) {
                            if (task.isSuccessful()) {
                                Toast.makeText(PWresetActivity.this, "Email has been sent successfully.", Toast.LENGTH_SHORT).show();
                                finish();
                                startActivity(new Intent(PWresetActivity.this, LoginActivity.class));
                            } else {
                                Toast.makeText(PWresetActivity.this, "Invalid email address.", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                  }
            }
        });
        tvSignin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(PWresetActivity.this,LoginActivity.class));
            }
        });
    }
    private void initializeGUI(){
        ivLogo = findViewById(R.id.ivLogLogo);
        ivPWreset = findViewById(R.id.ivPassReset);
        tvInfo = findViewById(R.id.tvPWinfo);
        tvSignin = findViewById(R.id.tvGoBack);
        atvEmail = findViewById(R.id.atvEmailRes);
        btnReset = findViewById(R.id.btnReset);

        firebaseAuth = FirebaseAuth.getInstance();
    }
}

Here use Firebase for store data in back-end. Firebase is Web socket based so its much faster than HTTP connection. Now we have to implement UI design for our application.For more see our other article also it will help you to make validation forms.

XML Layout – android login signup form

In Android we have use XML for design the pages. Manually we are design each page or drag components like button text something like this. Open the default layout of activity_main.xml file and add following code,

After that we have to create designs for each page like login page, signup page and forgot password page. So in below i will give the full source code of Android Login Signup form Material Design with Validation.

Download Source Code

Here you can download full source code of Android Login Signup Form. Click below button to get the code & if you are facing any issues just contact us for solve all the bugs. Moreover already we are fixed most of the issues from our end, so don’t worry about issues.

Leave a Reply