How to Create Login and Registration form in Android studio

Login and Registration form in Android studio Hindi 2021. in this video I have designed a login form and registration form UI design with Android studio. In this tutorial, we will learn how to create Login and Registration form in android. Android login and registration form is used to obtain credentials from the user.

We will create two activities.

  1. Login Activity
  2. Register Activity

Example of Login and Registration
Add the support library to the dependency section.

Add Dependency in gradle.app(module app)

gradle.app

 implementation 'com.google.android.material:material:1.0.0'
 implementation 'androidx.cardview:cardview:1.0.0'
<img loading=
plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.technicdude.registrationform"
        minSdkVersion 19
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.technicdude.registrationform">

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:roundIcon="@drawable/logo"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar">

        <activity
            android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity"/>
    </application>

</manifest>

LoginActivity.java

package com.technicdude.registrationform;

import android.content.Intent;
import android.util.Patterns;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputLayout;

public class LoginActivity extends AppCompatActivity {

    EditText email, password;
    Button login;
    TextView register;
    boolean isEmailValid, isPasswordValid;
    TextInputLayout emailError, passError;

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

        email = (EditText) findViewById(R.id.email);
        password = (EditText) findViewById(R.id.password);
        login = (Button) findViewById(R.id.login);
        register = (TextView) findViewById(R.id.register);
        emailError = (TextInputLayout) findViewById(R.id.emailError);
        passError = (TextInputLayout) findViewById(R.id.passError);

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SetValidation();
            }
        });

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // redirect to RegisterActivity
                Intent intent = new Intent(getApplicationContext(), RegisterActivity.class);
                startActivity(intent);
            }
        });
    }

    public void SetValidation() {
        // Check for a valid email address.
        if (email.getText().toString().isEmpty()) {
            emailError.setError(getResources().getString(R.string.email_error));
            isEmailValid = false;
        } else if (!Patterns.EMAIL_ADDRESS.matcher(email.getText().toString()).matches()) {
            emailError.setError(getResources().getString(R.string.error_invalid_email));
            isEmailValid = false;
        } else  {
            isEmailValid = true;
            emailError.setErrorEnabled(false);
        }

        // Check for a valid password.
        if (password.getText().toString().isEmpty()) {
            passError.setError(getResources().getString(R.string.password_error));
            isPasswordValid = false;
        } else if (password.getText().length() < 6) {
            passError.setError(getResources().getString(R.string.error_invalid_password));
            isPasswordValid = false;
        } else  {
            isPasswordValid = true;
            passError.setErrorEnabled(false);
        }

        if (isEmailValid && isPasswordValid) {
            Toast.makeText(getApplicationContext(), "Successfully", Toast.LENGTH_SHORT).show();
        }

    }

}

RegistrationActivity.java

In this RegisterActivity.java file, we have used the setError() method to display an error message to the user.

package com.technicdude.registrationform;
import android.content.Intent;
import android.util.Patterns;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputLayout;

public class RegisterActivity extends AppCompatActivity {

    EditText name, email, phone, password;
    Button register;
    TextView login;
    boolean isNameValid, isEmailValid, isPhoneValid, isPasswordValid;
    TextInputLayout nameError, emailError, phoneError, passError;

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

        name = (EditText) findViewById(R.id.name);
        email = (EditText) findViewById(R.id.email);
        phone = (EditText) findViewById(R.id.phone);
        password = (EditText) findViewById(R.id.password);
        login = (TextView) findViewById(R.id.login);
        register = (Button) findViewById(R.id.register);
        nameError = (TextInputLayout) findViewById(R.id.nameError);
        emailError = (TextInputLayout) findViewById(R.id.emailError);
        phoneError = (TextInputLayout) findViewById(R.id.phoneError);
        passError = (TextInputLayout) findViewById(R.id.passError);

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SetValidation();
            }
        });

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // redirect to LoginActivity
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
            }
        });
    }

    public void SetValidation() {
        // Check for a valid name.
        if (name.getText().toString().isEmpty()) {
            nameError.setError(getResources().getString(R.string.name_error));
            isNameValid = false;
        } else  {
            isNameValid = true;
            nameError.setErrorEnabled(false);
        }

        // Check for a valid email address.
        if (email.getText().toString().isEmpty()) {
            emailError.setError(getResources().getString(R.string.email_error));
            isEmailValid = false;
        } else if (!Patterns.EMAIL_ADDRESS.matcher(email.getText().toString()).matches()) {
            emailError.setError(getResources().getString(R.string.error_invalid_email));
            isEmailValid = false;
        } else  {
            isEmailValid = true;
            emailError.setErrorEnabled(false);
        }

        // Check for a valid phone number.
        if (phone.getText().toString().isEmpty()) {
            phoneError.setError(getResources().getString(R.string.phone_error));
            isPhoneValid = false;
        } else  {
            isPhoneValid = true;
            phoneError.setErrorEnabled(false);
        }

        // Check for a valid password.
        if (password.getText().toString().isEmpty()) {
            passError.setError(getResources().getString(R.string.password_error));
            isPasswordValid = false;
        } else if (password.getText().length() < 6) {
            passError.setError(getResources().getString(R.string.error_invalid_password));
            isPasswordValid = false;
        } else  {
            isPasswordValid = true;
            passError.setErrorEnabled(false);
        }

        if (isNameValid && isEmailValid && isPhoneValid && isPasswordValid) {
            Toast.makeText(getApplicationContext(), "Successfully", Toast.LENGTH_SHORT).show();
        }

    }

}

activity_login.xml

In the activity_register.xml file, we have used CardView, ImageView, EditText, etc.

<img loading=
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/img"
    android:gravity="center"
    android:padding="16dp"
    tools:context=".LoginActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <androidx.cardview.widget.CardView
            xmlns:Card_View="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:layout_margin="5dp"
            android:padding="10dp"
            Card_View:cardCornerRadius="5dp"
            Card_View:cardElevation="5dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="5dp"
                android:orientation="vertical">

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/emailError"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp">

                    <EditText
                        android:id="@+id/email"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:hint="@string/prompt_email"
                        android:inputType="textEmailAddress"
                        android:maxLines="1"
                        android:paddingStart="5dp"
                        android:singleLine="true"/>

                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/passError"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    app:passwordToggleEnabled="true">

                    <EditText
                        android:id="@+id/password"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:hint="@string/prompt_password"
                        android:inputType="textPassword"
                        android:maxLines="1"
                        android:paddingStart="5dp"
                        android:singleLine="true"/>

                </com.google.android.material.textfield.TextInputLayout>

                <Button
                    android:id="@+id/login"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_margin="20dp"
                    android:background="#2a7ee6"
                    android:text="@string/login"
                    android:textColor="@android:color/white"
                    android:textSize="20sp"/>

                <TextView
                    android:id="@+id/register"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:gravity="center"
                    android:text="@string/create_new"
                    android:textColor="@color/colorPrimary"
                    android:textSize="16sp"/>

            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </RelativeLayout>

    <ImageView
        android:id="@+id/profile"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-50dp"
        android:background="@drawable/round_background"
        android:padding="15dp"
        android:src="@drawable/profile"/>

</RelativeLayout>

activity_registration.xml

<img loading=
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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"
    android:background="@drawable/img"
    android:padding="16dp"
    android:scrollbarThumbVertical="@null"
    tools:context=".RegisterActivity">


    <androidx.cardview.widget.CardView
        xmlns:Card_View="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:padding="10dp"
        Card_View:cardCornerRadius="5dp"
        Card_View:cardElevation="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="5dp"
            android:orientation="vertical">

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/nameError"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

                <EditText
                    android:id="@+id/name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:hint="@string/name"
                    android:inputType="textNoSuggestions"
                    android:maxLines="1"
                    android:paddingStart="5dp"
                    android:singleLine="true"/>

            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/emailError"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

                <EditText
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:hint="@string/prompt_email"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:paddingStart="5dp"
                    android:singleLine="true"/>

            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/phoneError"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

                <EditText
                    android:id="@+id/phone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:hint="@string/phone_number"
                    android:maxLength="12"
                    android:inputType="number"
                    android:maxLines="1"
                    android:paddingStart="5dp"
                    android:singleLine="true"/>

            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/passError"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:passwordToggleEnabled="true"
                android:layout_marginTop="5dp">

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:hint="@string/prompt_password"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:paddingStart="5dp"
                    android:singleLine="true"/>

            </com.google.android.material.textfield.TextInputLayout>

            <Button
                android:id="@+id/register"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_margin="20dp"
                android:background="@drawable/button_gradient"
                android:text="@string/register"
                android:textColor="@android:color/white"
                android:textSize="16sp"/>

            <TextView
                android:id="@+id/login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:gravity="center"
                android:text="@string/not_register"
                android:textColor="@color/colorPrimary"
                android:textSize="16sp"/>

        </LinearLayout>
    </androidx.cardview.widget.CardView>

</ScrollView>

Create a button_gradient.xml file in the drawable folder.

/button_gradient.xmlCopy

<?xml version="1.0" encoding="utf-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="225"
        android:endColor="@android:color/holo_orange_dark"
        android:startColor="@android:color/holo_orange_light"/>
</shape>

Create a gradient.xml file in the drawable folder.

/gradient.xmlCopy

<?xml version="1.0" encoding="utf-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="225"
        android:endColor="@android:color/darker_gray"
        android:startColor="#044fab"/>
</shape>

Create a round_background.xml file in the drawable folder.

/round_background.xmlCopy

<?xml version="1.0" encoding="utf-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#fff6f6"/>
</shape>

Add colors in colors.xml file.

/values/colors.xmlCopy

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#2a7ee6</color>
    <color name="colorPrimaryDark">#76a5df</color>
    <color name="colorAccent">#ffff8800</color>
    <color name="zircon">#e0e6e4</color>
</resources>

Add strings in strings.xml file.

/values/strings.xmlCopy

<resources>
    <string name="app_name">TextInputLayout</string>
    <string name="prompt_email">Email</string>
    <string name="prompt_password">Password</string>
    <string name="login">Login</string>
    <string name="create_new">Click here for register</string>
    <string name="not_register">Not Register?</string>
    <string name="name">Name</string>
    <string name="phone_number">Phone Number</string>
    <string name="register">Register</string>
    <string name="name_error">Please enter your name</string>
    <string name="phone_error">Please enter your phone number</string>
    <string name="email_error">Please enter your email address</string>
    <string name="error_invalid_email">This email address is invalid</string>
    <string name="password_error">Please enter a password</string>
    <string name="error_invalid_password">Please enter a minimum password of 6 characters</string>
</resources>

Add themes in styles.xml file.

/values/styles.xmlCopy

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
	
    <style name="AppTheme.NoActionBar" >
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

GET FULL SOURCE CODE DOWNLOAD HERE

SOURCE CODE

<img src="download-btn.png" alt="download button ">

Conclusion

We have successfully Created Login Form application in android studio

YOUTUBE VIDEO

READ MORE ANDROID APPS

Wallpaper Android App- CLICK HERE

All IN ONE Status Saver App – CLICK HERE

Photo Video Maker Android App – CLICK HERE

Video Downloader Android App – CLICK HERE

College Student Portal System App – CLICK HERE

Call Recorder Android App – CLICK HERE

PDF App with firebase – CLICK HERE

BarChart Graph App – CLICK HERE

PDF Reader App with firebase – CLICK HERE

ShareIt Clone App – CLICK HERE

Material Design SignUp Form – CLICK HERE

Ludo Game Android App – CLICK HERE

Text on Photo Android App – CLICK HERE

Fast Pro VPN APP – CLICK HERE

3D Text Maker APP- CLICK HERE

Flappy bird Game – CLICK HERE

News Application – CLICK HERE

ECommerce Android App – CLICK HERE

YouTube copyright strike question CLICK HERE

ShareTweetShare

Cheers!

READ MORE

DeepCrazyWorld

Hey, I'm Deepika a professional blogger, web designer, Android developer and software engineer. I like to gain every type of knowledge that's why i have done many courses in different fields like engineering and technology. I love thrills and travelling to new places and hills.
5 2 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments