Practical No. 10
Practical No. 10
e1 = findViewById(R.id.e1);
e2 = findViewById(R.id.e2);
btn = findViewById(R.id.btn);
}
public void verify(View view){
String eu = e1.getText().toString();
String ep = e2.getText().toString();
if(eu.equals(user) && ep.equals(pass)){
Toast.makeText(this,"Login
Successfully!!",Toast.LENGTH_SHORT).show(
);
}
else {
Toast.makeText(this,"Login
Fails!!",Toast.LENGTH_SHORT).show();
}
}
}
Q. Write a program to create a login form for a android:layout_width="match_parent"
social networking site. android:layout_height="wrap_content">
<TextView
activity_main.xml android:layout_width="wrap_content"
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?> android:textSize="20dp"
<LinearLayout android:fontFamily="times new roman"
xmlns:android="http://schemas.android.com/apk/res android:text="Password : "/>
/android" <EditText
xmlns:app="http://schemas.android.com/apk/res- android:id="@+id/e2"
auto" android:inputType="textPassword"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/main" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_marginBottom="15dp"/>
android:layout_height="match_parent" </LinearLayout>
android:orientation="vertical" <Button
android:layout_margin="30dp" android:id="@+id/btn"
android:gravity="center" android:layout_width="wrap_content"
tools:context=".MainActivity"> android:layout_height="wrap_content"
android:text="Sign in"
<ImageView android:fontFamily="times new roman"
android:layout_width="match_parent" android:paddingHorizontal="80dp"
android:layout_height="80dp" android:onClick="verify"/>
android:src="@drawable/img"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent" MainActivity.java
android:layout_height="wrap_content">
<TextView package com.example.practicalno10_2;
android:layout_width="wrap_content"
android:layout_height="wrap_content" import static
android:text="Username" android.widget.Toast.LENGTH_SHORT;
android:textSize="20dp"
android:fontFamily="times new roman"/> import android.os.Bundle;
<EditText import android.view.View;
android:id="@+id/e1" import android.widget.Button;
android:layout_width="match_parent" import android.widget.EditText;
android:layout_height="wrap_content" import android.widget.Toast;
android:fontFamily="times new roman"
android:layout_marginBottom="15dp"/> import androidx.activity.EdgeToEdge;
</LinearLayout> import
<LinearLayout androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import
androidx.core.view.WindowInsetsCompat;
EditText e1,e2;
Button btn;
String user = "Admin";
String pass = "123";
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
e1 = findViewById(R.id.e1);
e2 = findViewById(R.id.e2);
btn = findViewById(R.id.btn);
}
public void verify(View view){
String eu = e1.getText().toString();
String ep = e2.getText().toString();
if(eu.equals(user) && ep.equals(pass)){
Toast.makeText(this,"Login
Successfully!!",Toast.LENGTH_SHORT).show(
);
}
else {
Toast.makeText(this,"Login
Fails!!",Toast.LENGTH_SHORT).show();
}
}