Prac 10
Prac 10
10
Xml code app:layout_constraintTop_toTopOf=
"parent" />
<?xml version="1.0"
<EditText
encoding="utf-8"?>
android:id="@+id/edittext"
<androidx.constraintlayout.widget.C
onstraintLayout
android:layout_width="wrap_conten
xmlns:android="http://schemas.andr
t"
oid.com/apk/res/android"
android:layout_height="wrap_conte
xmlns:app="http://schemas.android.
nt"
com/apk/res-auto"
android:layout_marginStart="125dp
xmlns:tools="http://schemas.android
"
.com/tools"
android:id="@+id/main"
android:layout_marginLeft="125dp"
android:layout_width="match_paren
android:layout_marginTop="48dp"
t"
android:ems="10"
android:layout_height="match_pare
android:inputType="textPersonNam
nt"
e"
tools:context=".MainActivity">
app:layout_constraintStart_toStartOf
<TextView
="parent"
android:id="@+id/textView"
android:layout_width="80dp"
app:layout_constraintTop_toTopOf=
android:layout_height="40dp"
"parent"/>
<TextView
android:layout_marginStart="29dp"
android:id="@+id/textView2"
android:layout_width="69dp"
android:layout_marginLeft="29dp"
android:layout_height="45dp"
android:layout_marginTop="48dp"
android:layout_marginStart="26dp"
android:text="Username"
android:layout_marginLeft="26dp"
app:layout_constraintStart_toStartOf
="parent"
android:layout_marginTop="137dp"
android:text="Password"
"
app:layout_constraintStart_toStartOf
="parent" android:layout_marginLeft="126dp"
app:layout_constraintTop_toTopOf= android:layout_marginTop="246dp"
"parent" /> android:text="Login"
<EditText
android:id="@+id/edittext2" app:layout_constraintStart_toStartOf
="parent"
android:layout_width="wrap_conten
t" app:layout_constraintTop_toTopOf=
"parent"/>
android:layout_height="wrap_conte </androidx.constraintlayout.widget.
nt" ConstraintLayout>
Java Code
android:layout_marginStart="126dp
" package com.example.prac10;
import android.os.Bundle;
android:layout_marginLeft="126dp" import android.view.View;
import android.widget.Button;
android:layout_marginTop="137dp" import android.widget.Toast;
android:ems="10" import
androidx.activity.EdgeToEdge;
android:inputType="textPassword" import
androidx.appcompat.app.AppCompa
app:layout_constraintStart_toStartOf tActivity;
="parent" import
androidx.core.graphics.Insets;
app:layout_constraintTop_toTopOf= import
"parent"/> androidx.core.view.ViewCompat;
<Button import
android:id="@+id/button" androidx.core.view.WindowInsetsCo
mpat;
android:layout_width="wrap_conten
t" public class MainActivity extends
AppCompatActivity {
android:layout_height="wrap_conte Button button;
nt" @Override
protected void onCreate(Bundle
android:layout_marginStart="126dp savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_m
ain);
button=(Button)
findViewById(R.id.button);
button.setOnClickListener(new
View.OnClickListener()
{
@Override
public void onClick(View
view)
{
Toast.makeText(MainActivity.this,"L
OGIN
SUCCESSFULLY!",Toast.LENGTH
_LONG).show();
}
});
}
}
Xml code
android:layout_height="wrap_conte
<?xml version="1.0"
nt"
encoding="utf-8"?>
android:text="Login"
<RelativeLayout
android:fontFamily="serif"
xmlns:android="http://schemas.andr
android:textSize="24sp"
oid.com/apk/res/android"
android:textStyle="bold"
xmlns:app="http://schemas.android.
android:paddingBottom="10dp"
com/apk/res-auto"
android:textColor="@android:color/
xmlns:tools="http://schemas.android
black" />
.com/tools"
<LinearLayout
android:id="@+id/main"
android:layout_width="match_paren
android:layout_width="match_paren
t"
t"
android:layout_height="wrap_conte
android:layout_height="match_pare
nt"
nt">
/>
android:orientation="horizontal"
<LinearLayout
android:gravity="center_vertical"
android:layout_width="match_paren
t"
android:paddingBottom="10dp">
<TextView
android:layout_height="wrap_conte
nt"
android:layout_width="wrap_conten
android:orientation="vertical"
t"
android:padding="20dp"
android:layout_height="wrap_conte
android:background="#AAFFFFFF"
nt"
android:text="Username: "
android:layout_centerInParent="true
"
android:fontFamily="serif"
android:gravity="center">
android:textSize="16sp"
<TextView
android:textColor="@android:color/
android:layout_width="wrap_conten
black"/>
t"
<EditText
android:text="Password"
android:id="@+id/username"
android:fontFamily="serif"
android:layout_width="0dp" android:textSize="16sp"
android:layout_height="wrap_conte android:textColor="@android:color/
nt" black"/>
<EditText
android:layout_weight="1"
android:hint="Enter android:id="@+id/password"
Username"
android:layout_width="0dp"
android:fontFamily="serif"
android:padding="10dp" android:layout_height="wrap_conte
nt"
android:background="@android:dra
wable/editbox_background" android:layout_weight="1"
android:hint="Enter
android:inputType="text"/> Password"
</LinearLayout>
<LinearLayout android:fontFamily="serif"
android:padding="10dp"
android:layout_width="match_paren
t" android:background="@android:dra
wable/editbox_background"
android:layout_height="wrap_conte
nt" android:inputType="textPassword"
/>
android:orientation="horizontal" </LinearLayout>
<Button
android:gravity="center_vertical" android:id="@+id/btnLogin"
android:paddingBottom="10dp"> android:layout_width="match_paren
<TextView t"
android:layout_width="wrap_conten android:layout_height="wrap_conte
t" nt"
android:text="Login"
android:layout_height="wrap_conte android:fontFamily="serif"
nt" android:textSize="16sp"
import
android:textColor="@android:color/ androidx.core.graphics.Insets;
black" import
android:paddingTop="10dp" androidx.core.view.ViewCompat;
/> import
<TextView androidx.core.view.WindowInsetsCo
android:id="@+id/message" mpat;
public class MainActivity extends
android:layout_width="wrap_conten AppCompatActivity {
t" EditText username, password;
Button btnLogin;
android:layout_height="wrap_conte TextView message;
nt"
android:text="" @Override
android:fontFamily="serif" protected void onCreate(Bundle
android:textSize="16sp" savedInstanceState) {
android:textColor="@android:color/ super.onCreate(savedInstanceState);
black"
android:paddingTop="10dp" setContentView(R.layout.activity_m
/> ain);
</LinearLayout> username =
</RelativeLayout> findViewById(R.id.username);
password =
findViewById(R.id.password);
Java Code btnLogin =
package findViewById(R.id.btnLogin);
com.example.prac10_1;import message =
android.os.Bundle; findViewById(R.id.message);
import android.view.View;
import android.widget.Button; btnLogin.setOnClickListener(new
import android.widget.EditText; View.OnClickListener() {
import android.widget.TextView; @Override
import android.graphics.Color; public void onClick(View v)
import {
androidx.activity.EdgeToEdge; String user =
import username.getText().toString();
androidx.appcompat.app.AppCompa String pass =
tActivity; password.getText().toString();
if (user.equals("Manasi")
&& pass.equals("1234")) {
//Login successful
message.setText("Login
Successful");
message.setTextColor(Color.parseC
olor("#388E3C")); //green color
} else {
//Login Failed...
message.setText("Invalid Username
or Password");
message.setTextColor(Color.parseC
olor("#D32F2F")); //Red color
}
//Show the Message
message.setVisibility(View.VISIBLE
);
}
});
}
}