0% found this document useful (0 votes)
38 views7 pages

Practical 10: Android Login UI Code

The document contains XML and Java code for an Android application that implements a login interface. It includes layout definitions for EditText fields for username and password, and a Button for login, along with the corresponding Java code to handle the login logic. The application displays a success or failure message based on the entered credentials.

Uploaded by

Kolekar Yashraj
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)
38 views7 pages

Practical 10: Android Login UI Code

The document contains XML and Java code for an Android application that implements a login interface. It includes layout definitions for EditText fields for username and password, and a Button for login, along with the corresponding Java code to handle the login logic. The application displays a success or failure message based on the entered credentials.

Uploaded by

Kolekar Yashraj
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

Practical No.

10
Xml code app:layout_constraintTop_toTopOf=
"parent" />
<?xml version="1.0"
<EditText
encoding="utf-8"?>
android:id="@+id/edittext"
<[Link].C
onstraintLayout
android:layout_width="wrap_conten
xmlns:android="[Link]
t"
[Link]/apk/res/android"
android:layout_height="wrap_conte
xmlns:app="[Link]
nt"
com/apk/res-auto"
android:layout_marginStart="125dp
xmlns:tools="[Link]
"
.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 </[Link].
nt" ConstraintLayout>
Java Code
android:layout_marginStart="126dp
" package [Link].prac10;
import [Link];
android:layout_marginLeft="126dp" import [Link];
import [Link];
android:layout_marginTop="137dp" import [Link];
android:ems="10" import
[Link];
android:inputType="textPassword" import
[Link]
app:layout_constraintStart_toStartOf tActivity;
="parent" import
[Link];
app:layout_constraintTop_toTopOf= import
"parent"/> [Link];
<Button import
android:id="@+id/button" [Link]
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) {
[Link](savedInstanceState);

setContentView([Link].activity_m
ain);
button=(Button)
findViewById([Link]);
[Link](new
[Link]()
{
@Override
public void onClick(View
view)
{

[Link]([Link],"L
OGIN
SUCCESSFULLY!",[Link]
_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="[Link]
android:textSize="24sp"
[Link]/apk/res/android"
android:textStyle="bold"
xmlns:app="[Link]
android:paddingBottom="10dp"
com/apk/res-auto"
android:textColor="@android:color/
xmlns:tools="[Link]
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/ [Link];
black" import
android:paddingTop="10dp" [Link];
/> import
<TextView [Link]
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/ [Link](savedInstanceState);
black"
android:paddingTop="10dp" setContentView([Link].activity_m
/> ain);
</LinearLayout> username =
</RelativeLayout> findViewById([Link]);
password =
findViewById([Link]);
Java Code btnLogin =
package findViewById([Link]);
[Link].prac10_1;import message =
[Link]; findViewById([Link]);
import [Link];
import [Link]; [Link](new
import [Link]; [Link]() {
import [Link]; @Override
import [Link]; public void onClick(View v)
import {
[Link]; String user =
import [Link]().toString();
[Link] String pass =
tActivity; [Link]().toString();
if ([Link]("Manasi")
&& [Link]("1234")) {
//Login successful
[Link]("Login
Successful");

[Link]([Link]
olor("#388E3C")); //green color
} else {
//Login Failed...

[Link]("Invalid Username
or Password");

[Link]([Link]
olor("#D32F2F")); //Red color
}
//Show the Message

[Link]([Link]
);
}
});
}
}

You might also like