Exp27 MAD

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

• Title : Exp27_St1_08 :- Write a program to create the login form and display login

successful/ Unsuccessful toastmessage.


activity_main.xml :-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Login Form"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_marginTop="140dp" />

<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"
android:textSize="25dp"
android:layout_marginTop="200dp"
android:layout_marginLeft="20dp" />

<EditText
android:id="@+id/user"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="200dp"
android:layout_marginRight="5dp"
android:layout_toEndOf="@+id/username" />

<TextView
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:textSize="25dp"
android:layout_below="@+id/username"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp" />

<EditText
android:id="@+id/pass"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_toRightOf="@+id/password"
android:layout_marginTop="260dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp" />

<Button
android:id="@+id/login"
android:layout_width="123dp"
android:layout_height="wrap_content"
android:layout_below="@id/pass"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="@color/white"
android:text="LOGIN" />

</RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java :-
package com.example.exp27_st1_08;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button login;
EditText uname, pwd;

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

login = findViewById(R.id.login);
uname = findViewById(R.id.user);
pwd = findViewById(R.id.pass);

login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (uname.getText().toString().equals("LESP") &&
pwd.getText().toString().equals("Pass@123")) {
Toast.makeText(MainActivity.this, "Login Successful",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Login Unsuccessful",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

• Output :-

You might also like