Skip to main content
Android UI Design with Kotlin
CHAPTER 13 Beginner

Designing Forms and Authentication Screens

Updated: May 31, 2026
5 min read

# CHAPTER 13

Designing Forms and Authentication Screens

1. Introduction

Forms are often the point of highest friction in any app. Whether it is a login screen, a signup flow, or a checkout page, if the UI is confusing or clunky, users will abandon the app. In Android, the standard EditText widget is functional, but visually bare. To create modern, accessible forms, we use TextInputLayout from the Material Components library. In this chapter, we will design beautiful authentication screens complete with floating labels, error states, and password toggles.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Use TextInputLayout to wrap your input fields.
  • Customize the style of input fields (Filled vs. Outlined).
  • Implement password visibility toggles (the "eye" icon).
  • Design clear error states and form validation feedback.
  • Build a complete Login/Signup UI.

3. Introducing TextInputLayout

TextInputLayout acts as a wrapper around a TextInputEditText. It provides the modern "floating label" effect: when the user taps the field, the hint text shrinks and floats to the top, making room for the user's input while keeping the context visible.
xml
123456789101112
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Email Address"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress" />

</com.google.android.material.textfield.TextInputLayout>

4. Customizing the Input Fields

Material Design provides two primary styles for input fields:
  • FilledBox (style="...FilledBox"): A solid background with a dark bottom indicator line. Great for forms with many fields.
  • OutlinedBox (style="...OutlinedBox"): A clean, rounded stroke border around the entire field. Great for simple, high-impact forms like Login screens.

Customizing Colors: You can change the outline color or the floating label color by customizing attributes like app:boxStrokeColor and app:hintTextColor.

5. Password Fields and Icons

Typing a password on a mobile device is error-prone. You should always provide a way for the user to see what they are typing. TextInputLayout makes this trivial:
xml
123456789101112
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password"
    app:endIconMode="password_toggle"> <!-- This adds the Eye icon! -->

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword" />

</com.google.android.material.textfield.TextInputLayout>

You can also add icons to the *start* of the field using app:startIconDrawable="@drawable/ic_lock".

6. Error States and Form Validation

When a user makes a mistake (e.g., entering an invalid email), the UI must clearly communicate the error. Do not rely on "Toast" messages. Display the error directly under the offending field.

In XML, enable errors: app:errorEnabled="true"

In your Kotlin code, set the error text:

kotlin
12345
val emailLayout = findViewById<TextInputLayout>(R.id.emailInputLayout)
// If email is invalid:
emailLayout.error = "Please enter a valid email address."
// To clear the error:
emailLayout.error = null

When error is set, the outline and the floating label automatically turn red (or your defined error color).

7. Mini Project: Authentication Screen

Let's assemble a beautiful Login Screen using ConstraintLayout, a hero image, two Outlined TextInputs, and a Material Button.
xml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="24dp"
    android:background="#FFFFFF">

    <!-- Hero Image -->
    <ImageView
        android:id="@+id/loginImage"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/ic_secure_login"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginTop="32dp"/>

    <TextView
        android:id="@+id/welcomeText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome Back"
        android:textSize="28sp"
        android:textStyle="bold"
        android:layout_marginTop="24dp"
        app:layout_constraintTop_toBottomOf="@+id/loginImage"
        app:layout_constraintStart_toStartOf="parent"/>

    <!-- Email Field -->
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/emailLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email Address"
        android:layout_marginTop="24dp"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        app:startIconDrawable="@drawable/ic_email"
        app:layout_constraintTop_toBottomOf="@+id/welcomeText">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress" />
    </com.google.android.material.textfield.TextInputLayout>

    <!-- Password Field -->
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/passwordLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:layout_marginTop="16dp"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        app:startIconDrawable="@drawable/ic_lock"
        app:endIconMode="password_toggle"
        app:layout_constraintTop_toBottomOf="@+id/emailLayout">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    </com.google.android.material.textfield.TextInputLayout>

    <!-- Login Button -->
    <com.google.android.material.button.MaterialButton
        android:id="@+id/loginButton"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:text="LOGIN"
        android:layout_marginTop="32dp"
        app:cornerRadius="8dp"
        app:layout_constraintTop_toBottomOf="@+id/passwordLayout" />

</androidx.constraintlayout.widget.ConstraintLayout>

8. Design Principles

  • Appropriate Input Types: Always set android:inputType. If asking for an email, textEmailAddress shows the "@" symbol on the keyboard. If asking for a phone number, phone shows the dialpad.
  • Clear Call to Action (CTA): The submit button (e.g., LOGIN) should be the most visually prominent element on the screen.
  • Avoid Clutter: Only ask for the information you absolutely need.

9. Common Mistakes

  • Hiding Hints: Using a standard EditText where the placeholder text disappears once the user types. If they forget what field they are filling, they have to delete their input to see the hint again. TextInputLayout solves this.
  • Tiny Touch Targets: Making input fields too short. The Material recommendation is a minimum height of 56dp for text inputs.

10. Best Practices

  • Auto-focus the first input field when the screen opens so the keyboard pops up immediately, saving the user a tap.
  • Provide a "Forgot Password?" link positioned logically near the password field or the login button.

11. Exercises

  1. 1. Modify the inputType of the email field to text and test it on an emulator. Notice how the keyboard changes. Then change it back to textEmailAddress.
  1. 2. Add a "Forgot Password?" TextView below the Password input layout, aligned to the End (right) of the parent.

12. UI Design Challenges

Challenge: Design a Signup screen that includes: First Name, Last Name, Email, Password, and Confirm Password. Put the First Name and Last Name fields on the same horizontal row using ConstraintLayout (each taking 0dp width and chained together), and the rest stacked vertically below.

13. MCQ Quiz with Answers

Question 1

What is the primary visual benefit of TextInputLayout over a standard EditText?

Question 2

Which attribute easily adds an "eye" icon to toggle password visibility?

14. Interview Questions

  • Q: How does setting android:inputType affect the user experience?
  • Q: Explain how you would display a validation error on a specific text field without using a Toast or Dialog.

15. Summary

In this chapter, we conquered form design. We moved away from basic, unstyled inputs and embraced the powerful TextInputLayout to create robust, accessible, and beautifully styled fields. We learned how to toggle passwords, show clear error states, and combine it all into a professional authentication UI.

16. Next Chapter Recommendation

Once the user logs in, they need to be greeted by a powerful, informative screen. In Chapter 14: Creating Dashboard and Home Screens, we will explore how to design card-based dashboards and statistics widgets that deliver immediate value to the user.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·