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

27 Practical

The document describes an Android login screen application with an activity_main.xml layout file containing EditText fields for a username and password, a login button, and two TextView fields. The MainActivity.java file contains code to retrieve the username and password on button click, check for a hardcoded valid login, and display Toast messages for successful or failed login attempts.

Uploaded by

shrutinimbekar05
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)
21 views4 pages

27 Practical

The document describes an Android login screen application with an activity_main.xml layout file containing EditText fields for a username and password, a login button, and two TextView fields. The MainActivity.java file contains code to retrieve the username and password on button click, check for a hardcoded valid login, and display Toast messages for successful or failed login attempts.

Uploaded by

shrutinimbekar05
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

27th Practical

1) Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="16dp">

<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="Username"
android:inputType="text" />

<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="Password"
android:inputType="textPassword" />

<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv2"/>
</LinearLayout>

MainActivity.java
package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText editTextUsername, editTextPassword;
Button buttonLogin;
TextView tv;

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

editTextUsername = findViewById(R.id.editTextUsername);
editTextPassword = findViewById(R.id.editTextPassword);
buttonLogin = findViewById(R.id.buttonLogin);
tv=findViewById(R.id.tv);

buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String username = editTextUsername.getText().toString();
String password = editTextPassword.getText().toString();
if (username.equals("Admin")&& password.equals("123")) {
Toast.makeText(MainActivity.this, "Login Succesfull",
Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(MainActivity.this, "Unsuccesful",
Toast.LENGTH_SHORT).show();
}

}
});
}
}
Output: -

You might also like