Basic Android Login Form Example - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
In this tutorials, we are going to see how to create a simple Android Login Form using Android Studio.
Android SDK Version 27
Android AppCompact-v7:27.0.1
Gradle
Android Studio 3.1
Creating a simple Android login screen under Linear Layout.
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.onlinetutorialspoint.official.simplelogin"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Creating a basic login form layout using LinearLayout having one text box, password and Login button.
<?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="com.onlinetutorialspoint.official.simplelogin.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"

    android:layout_centerInParent="true">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="UserName"
        android:id="@+id/username"/>
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="password"
    android:id="@+id/password"
    android:inputType="textPassword"
    />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login"
        android:background="#3f76ff"
        android:textColor="#fff"
        android:id="@+id/login"/>
    
</LinearLayout>

</RelativeLayout>

Creating MainActivity.java, responsible to read the input from the about layout and validate the user inputs.
package com.onlinetutorialspoint.official.simplelogin;

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.Toast;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {
EditText username,password;
Button login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        username=findViewById(R.id.username);
        password=findViewById(R.id.password);
        login=findViewById(R.id.login);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(Objects.equals(username.getText().toString(), "admin")&&Objects.equals(password.getText().toString(),"admin"))
                {
                    Toast.makeText(MainActivity.this,"You have Authenticated Successfully",Toast.LENGTH_LONG).show();

                }else
                {
                    Toast.makeText(MainActivity.this,"Authentication Failed",Toast.LENGTH_LONG).show();
                }

            }
        });

    }
}

Run Android Virtual Device (AVD):
Giving Valid Credentials: admin – admin
Giving invalid credentials:
Happy Learning 🙂

Java Swing Login Example
Spring MVC Login Form Example Tutorials
Spring Boot Validation Login Form Example
Python Selenium Automate the Login Form
Spring Hibernate Example
PHP Form Handling Example
Spring Boot MVC Example Tutorials
Spring Form Custom Validation Example
How to add Android Device to Android Studio
Spring MVC Form Validation Example
Android Hello World Example
How to install Android Studio on Windows 10
How to Configure Android Studio
How to install Android SDK Windows 10 Manual Process
Basic Hibernate Example with XML Configuration

Java Swing Login Example
Spring MVC Login Form Example Tutorials
Spring Boot Validation Login Form Example
Python Selenium Automate the Login Form
Spring Hibernate Example
PHP Form Handling Example
Spring Boot MVC Example Tutorials
Spring Form Custom Validation Example
How to add Android Device to Android Studio
Spring MVC Form Validation Example
Android Hello World Example
How to install Android Studio on Windows 10
How to Configure Android Studio
How to install Android SDK Windows 10 Manual Process
Basic Hibernate Example with XML Configuration






nisha
August 10, 2018 at 1:06 pm - Reply 

Its actually a great and helpful piece of information. I really want to learn android, I have entered in android with a great curiosity but today its become very difficult for me to learn,  So please recommend me a startup....!
Thank You










nisha
August 10, 2018 at 1:06 pm - Reply 

Its actually a great and helpful piece of information. I really want to learn android, I have entered in android with a great curiosity but today its become very difficult for me to learn,  So please recommend me a startup....!
Thank You




Its actually a great and helpful piece of information. I really want to learn android, I have entered in android with a great curiosity but today its become very difficult for me to learn,  So please recommend me a startup....!