Introduction
A Login Form is commonly used in applications to allow users to enter their credentials such as username and password.
In Android development, various UI controls can be used to design a login interface:
- TextView – Displays text labels.
- EditText – Allows the user to enter text.
- Button – Performs login action.
- CheckBox – Used for options like Remember Me.
- RadioButton – Used to select a single option from a group.
This practical demonstrates how to create a simple login form using these UI controls.
Step 1: Create a New Android Project
- Open Android Studio
- Click New Project
- Select Empty Activity
- Choose Java as the programming language
- Click Finish
Step 2: activity_main.xml
Open res → layout → activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:padding="24dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="Welcome Back"
android:textSize="28sp"
android:textStyle="bold"
android:textColor="#333333"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_top_toTopOf="parent" />
<EditText
android:id="@+id/etUsername"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_marginTop="40dp"
android:background="@android:drawable/editbox_background"
android:hint="Username or Email"
android:inputType="textEmailAddress"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_top_toBottomOf="@+id/tvTitle" />
<EditText
android:id="@+id/etPassword"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_marginTop="16dp"
android:background="@android:drawable/editbox_background"
android:hint="Password"
android:inputType="textPassword"
android:paddingStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_top_toBottomOf="@+id/etUsername" />
<Button
android:id="@+id/btnLogin"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginTop="32dp"
android:text="Login"
android:backgroundTint="#6200EE"
android:textColor="@android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_top_toBottomOf="@+id/etPassword" />
<TextView
android:id="@+id/tvForgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Forgot Password?"
android:textColor="#6200EE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_top_toBottomOf="@+id/btnLogin" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output
When the application runs:
- User enters Username and Password
- User selects role (User/Admin) using RadioButton
- User can enable Remember Me using CheckBox
- Clicking the Login button displays entered details using a Toast message
Conclusion
In this practical, we developed a Login Form using different Android UI controls such as TextView, EditText, Button, CheckBox, and RadioButton. These controls help in designing interactive forms in Android applications.