Experiment 04 – Login Window
Aim: To write a program to design login window using UI controls in Android Studio.
Theory:
● Widgets in Android:
There are a lot of android widgets such as Button, EditText, AutoCompleteTextView,
ToggleButton, DatePicker, TimePicker, ProgressBar etc.
● Android Button
This is used for event handling when clicked.
● Android Toast
Displays information for the short duration of time.
● Custom Toast
We are able to customize the toast, such as we can display image on the toast
● ToggleButton
It has two states ON/OFF.
● CheckBox
This is a type of two state button either checked or unchecked. There can be a lot of usage of
checkboxes. For example, it can be used to know the hobby of the user, activate/deactivate the
specific action etc.
● AlertDialog
AlertDialog displays an alert dialog containing the message with OK and Cancel buttons.
● Spinner
Spinner displays the multiple options, but only one can be selected at a time.
● AutoCompleteTextView
Android AutoCompleteTextView completes the word based on the reserved words, so no need to
write all the characters of the word. Android AutoCompleteTextView is an editable text field, it
displays a list of suggestions in a drop down menu from which user can select only one
suggestion or value.
● RatingBar
RatingBar displays the rating bar.
● DatePicker
Datepicker displays the datepicker dialog that can be used to pick the date.
● TimePicker
TimePicker displays the timepicker dialog that can be used to pick the time.
● ProgressBar
ProgressBar displays progress task.
Implementation:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private EditText editTextUsername, editTextPassword;
private Button buttonLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Initialize UI elements
editTextUsername = findViewById([Link]);
editTextPassword = findViewById([Link]);
buttonLogin = findViewById([Link]);
// Set a click listener for the login button
[Link](new [Link]() {
@Override
public void onClick(View view) {
// Retrieve entered username and password
String username = [Link]().toString();
String password = [Link]().toString();
// Implement authentication logic here
if ([Link]("Admin") && [Link]("123")) {
// Successful login
[Link]([Link], "Login successful", Toast.LENGTH_SHORT).show();
} else {
// Failed login
[Link]([Link], "Invalid username or password",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="16dp">
<!-- Username EditText -->
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="Username"
android:inputType="text" />
<!-- Password EditText -->
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="Password"
android:inputType="textPassword" />
<!-- Login Button -->
<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
</LinearLayout>
Output:
Conclusion: We were able to implement login window using UI controls in Android Studio
For Faculty Use
Correction Formative Timely
Parameters Assessment Attendance /
[40%] completion of
Learning
Practical [ 40%]
Attitude
[20%]
Marks
Obtained