0% found this document useful (0 votes)
15 views4 pages

Mad Practical 27

The document outlines the creation of a login form using XML and Java for an Android application. It includes the layout design in XML with fields for username and password, and a button to submit the login. The Java code handles the login logic, displaying a toast message for successful or unsuccessful login attempts based on predefined credentials.

Uploaded by

kolekarsiddhi056
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)
15 views4 pages

Mad Practical 27

The document outlines the creation of a login form using XML and Java for an Android application. It includes the layout design in XML with fields for username and password, and a button to submit the login. The Java code handles the login logic, displaying a toast message for successful or unsuccessful login attempts based on predefined credentials.

Uploaded by

kolekarsiddhi056
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/ 4

X.

Exercise

1. Write a program to create the login form and display login successful/
Unsuccessful toastmessage.
Activity_main.xml
<?xml version="1.0" encoding="utf-
8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/andr
oid"
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="@android:color/white"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<ImageView

android:id="@+id/imageView2"
android:layout_width="160dp"
android:layout_height="140dp"
app:srcCompat="@drawable/user" />

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:layout_marginRight="10dp"
android:background="#040404"
android:textColor="@android:color/whi
te"
android:textColorHint="#FFFDFD"
android:hint="Username"
android:inputType="text"
android:padding="10dp" />

<EditText

android:id="@+id/editText2"
android:layout_width="match_parent
"
android:layout_height="wrap_conten
t"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#040404"
android:textColor="@android:color/
white"
android:hint="Password"
android:inputType="textPassword"
android:padding="10dp"

android:textColorHint="#FFFDFD" />

<Button
android:id="@+id/button1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:layout_marginRight="10dp"
android:background="#FFC30E"
android:padding="10dp"
android:text="Log In"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
MainActivity.java

import
androidx.appcompat.app.AppCompatAc
tivity; import
android.annotation.SuppressLint;
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 u, p;
Button s;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
u = findViewById(R.id.editText1);
p = findViewById(R.id.editText2);
s = findViewById(R.id.button1);
s.setOnClickListener(new View.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
if (Objects.equals(u.getText().toString(),
"Ruchira Patil") &&
Objects.equals(p.getText().toString(), "a123!"))
{
Toast.makeText(MainActivity.this, "Login
Successfully",Toast.LENGTH_LONG).show();

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

You might also like