0% found this document useful (0 votes)
77 views2 pages

Practical No 27

The document contains code for a login screen Android application. The activity_main.xml layout file defines the user interface which includes fields for a name, username, password and a login button. The MainActivity Java code handles the login button click event by checking the entered username and password and displaying a toast message to indicate a successful or unsuccessful login attempt.

Uploaded by

atharvabutte03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

Practical No 27

The document contains code for a login screen Android application. The activity_main.xml layout file defines the user interface which includes fields for a name, username, password and a login button. The MainActivity Java code handles the login button click event by checking the entered username and password and displaying a toast message to indicate a successful or unsuccessful login attempt.

Uploaded by

atharvabutte03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No 27

Q1.
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">

<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="162dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Atharva Butte"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<LinearLayout
android:layout_width="414dp"
android:layout_height="657dp"
android:layout_marginTop="36dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Login"
android:textSize="34sp" />

<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:src="@drawable/img"/>

<Space
android:layout_width="match_parent"
android:layout_height="70dp" />

<EditText
android:id="@+id/unm"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="text"
android:text="Enter Name" />

<EditText
android:id="@+id/pass"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="text"
android:text="Enter Password" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="20dp"
android:layout_marginRight="60dp"
android:onClick="submit"
android:text="Login" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.practical26;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class MainActivity extends AppCompatActivity {


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

public void submit(View view) {


if (((EditText) findViewById(R.id.unm)).getText().toString().equals("Atharva
Butte")) {
if (((EditText)
findViewById(R.id.pass)).getText().toString().equals("baban@123"))
Toast.makeText(MainActivity.this, "Login Sucessfull",
Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this, "Login Unsucessfull!\n Wrong
Password", Toast.LENGTH_LONG).show();
}else
Toast.makeText(MainActivity.this, "Login Unsucessfull!",
Toast.LENGTH_LONG).show();

}
}

You might also like