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

Exp 6

The document contains an XML layout for a login screen and a Java class for handling login functionality in an Android application. The layout includes a CardView with EditTexts for username and password, and a login button. The Java class checks the entered credentials and displays a toast message indicating whether the login was successful or failed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Exp 6

The document contains an XML layout for a login screen and a Java class for handling login functionality in an Android application. The layout includes a CardView with EditTexts for username and password, and a login button. The Java class checks the entered credentials and displays a toast message indicating whether the login was successful or failed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Activity_main.

xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
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:orientation="vertical"
android:gravity="center"
android:background="@drawable/login"
tools:context=".MainActivity">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
app:cardCornerRadius="30dp"
app:cardElevation="20dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="24dp"
android:background="@drawable/custom_edittext">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/loginText"
android:textSize="36sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#135a84"/>

<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/username"
android:background="@drawable/custom_edittext"
android:layout_marginTop="40dp"
android:padding="8dp"
android:hint="Username"
android:drawableLeft="@drawable/ic_baseline_person_24"
android:textColor="@color/black"
android:drawablePadding="8dp"/>

<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/password"
android:background="@drawable/custom_edittext"
android:layout_marginTop="20dp"
android:inputType="textPassword"
android:padding="8dp"
android:hint="Password"
android:drawableLeft="@drawable/ic_baseline_lock_24"
android:textColor="@color/black"
android:drawablePadding="8dp"/>

<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Login"
android:id="@+id/loginButton"
android:textSize="18sp"
android:layout_marginTop="30dp"
android:backgroundTint="#135a84"
app:cornerRadius = "20dp"/>

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>
MainActivity.java

package com.example.exp6;

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 {

private EditText username;


private EditText password;
private Button loginButton;

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

username = findViewById(R.id.username);
password = findViewById(R.id.password);
loginButton = findViewById(R.id.loginButton);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = username.getText().toString().trim();
String pass = password.getText().toString().trim();

if (user.equals("Deepak") && pass.equals("Pass")) {


Toast.makeText(MainActivity.this, "Login Successful!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Login Failed!",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output

You might also like