Skip to content
intermediate Phase 3 · UI with XML & Views

Material Design

Apply Material Design 3 components: buttons, cards, bottom navigation, FAB, and snackbars.

50m
0 problems
Topic Progress 0%

Material Design 3 Fundamentals

What is Material Design 3?

Material Design 3 (Material You) is Google's design system for building consistent, accessible UIs. It provides pre-built components, color schemes, and motion patterns that look native on Android devices.

Adding Material Components

Add the Material dependency to your module's build.gradle:

dependencies {
    implementation("com.google.android.material:material:1.12.0")
}

Your app theme must extend a Material theme:

<!-- res/values/themes.xml -->
<style name="Theme.MyApp" parent="Theme.Material3.DayNight">
    <item name="colorPrimary">@color/purple_500</item>
    <item name="colorOnPrimary">@color/white</item>
    <item name="colorSecondary">@color/teal_200</item>
</style>

Material Buttons

Material provides several button variants for different emphasis levels:

<!-- Filled button — primary action -->
<com.google.android.material.button.MaterialButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save" />

<!-- Outlined button — secondary action -->
<com.google.android.material.button.MaterialButton
    style="@style/Widget.Material3.Button.OutlinedButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Cancel" />

<!-- Text button — low emphasis -->
<com.google.android.material.button.MaterialButton
    style="@style/Widget.Material3.Button.TextButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Learn More" />

Choose button emphasis based on the action's importance: filled for primary, outlined for secondary, text for tertiary.

Cards

Cards group related content with rounded corners and optional elevation:

<com.google.android.material.card.MaterialCardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    app:cardCornerRadius="12dp"
    app:cardElevation="2dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="16dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Order #1234"
            android:textAppearance="?attr/textAppearanceTitleMedium" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delivered yesterday"
            android:textAppearance="?attr/textAppearanceBodyMedium" />
    </LinearLayout>
</com.google.android.material.card.MaterialCardView>

Note the use of ?attr/textAppearanceTitleMedium — these are Material's built-in text styles that automatically match the current theme.

FAB, Bottom Navigation, and Snackbars

Floating Action Button (FAB)

The FAB represents the primary action on a screen. It floats above content and uses a distinct color to draw attention:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    android:src="@drawable/ic_add"
    app:layout_anchor="@id/recyclerView"
    app:layout_anchorGravity="bottom|end" />

Use app:layout_anchor to attach the FAB to another view — it automatically repositions when the anchor moves (e.g., when a Snackbar appears).

For an Extended FAB with a label:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
    android:id="@+id/extendedFab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Compose"
    android:src="@drawable/ic_edit" />

Bottom Navigation

Bottom navigation provides top-level destinations in your app. Use it for 3-5 destinations:

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottomNav"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:menu="@menu/bottom_nav_menu" />

Define the menu items in res/menu/bottom_nav_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_home"
        android:title="Home" />
    <item
        android:id="@+id/nav_search"
        android:icon="@drawable/ic_search"
        android:title="Search" />
    <item
        android:id="@+id/nav_profile"
        android:icon="@drawable/ic_person"
        android:title="Profile" />
</menu>

Handle navigation in code:

binding.bottomNav.setOnItemSelectedListener { item ->
    when (item.itemId) {
        R.id.nav_home -> { navigateToHome(); true }
        R.id.nav_search -> { navigateToSearch(); true }
        R.id.nav_profile -> { navigateToProfile(); true }
        else -> false
    }
}

Snackbars

Snackbars provide brief feedback at the bottom of the screen. Unlike Toasts, they support action buttons and can be dismissed by swiping:

Snackbar.make(binding.root, "Item deleted", Snackbar.LENGTH_LONG)
    .setAction("UNDO") {
        // Restore the item
    }
    .show()

Snackbar vs Toast: Snackbar is better because it supports user interaction (action buttons), can be dismissed, and doesn't disappear while the user is reading it. Toasts are fire-and-forget — avoid them in modern apps.

Snackbar vs Dialog: Use Snackbar for non-blocking feedback. Use a Dialog only when the user must make a decision before continuing.

Quiz

1. When should you use a filled MaterialButton vs a text button?

Question 1 options

2. How many top-level destinations should you have in a BottomNavigationView?

Question 2 options

3. What is the key difference between a Snackbar and a Toast?

Question 3 options

4. Why should you use ?attr/textAppearanceTitleMedium instead of hardcoded text sizes?

Question 4 options

Flashcards

Question

What are the three button emphasis levels in Material Design 3?

Answer

Filled (primary action), Outlined (secondary action), and Text (tertiary/low-emphasis action).

Question

When should you use a FloatingActionButton vs a regular button?

Answer

FAB for the single primary action on a screen (compose, add, create). Regular buttons for actions within content flows.

Question

How many destinations should BottomNavigationView have?

Answer

3 to 5 top-level destinations. Fewer than 3 suits a different component; more than 5 causes crowding.

Question

Why use Snackbar instead of Toast for user feedback?

Answer

Snackbars support action buttons (like Undo), can be swiped away, and provide a better UX. Toasts are non-interactive and fire-and-forget.

Revision Notes

Key Takeaways

  • 1. Material Design 3 provides a complete design system — components, colors, and typography work together
  • 2. Match button emphasis to action importance — filled for primary, text for tertiary
  • 3. Use app:layout_anchor on FABs so they automatically reposition when Snackbars appear
  • 4. BottomNavigationView works best with 3-5 top-level destinations
  • 5. Always prefer Snackbar over Toast for user feedback

Interview Tips

  • Explain Material Design's emphasis system — how component prominence communicates importance
  • Be ready to justify component choices: FAB vs button, Snackbar vs Toast vs Dialog
  • Know when BottomNavigationView is appropriate vs navigation drawer or tab layout
  • Discuss how Material theming with color attributes enables dark mode without code changes

Cheat Sheet

Material Design 3 Cheat Sheet

Setup:

  • Add com.google.android.material:material dependency
  • Theme must extend Theme.Material3.DayNight

Components:

  • MaterialButton: Filled (primary), Outlined (secondary), Text (tertiary)
  • MaterialCardView: use app:cardCornerRadius and app:cardElevation
  • FAB: use app:layout_anchor for automatic repositioning
  • BottomNavigationView: 3-5 destinations, handle with setOnItemSelectedListener
  • Snackbar: use instead of Toast, supports action buttons

Text Styles:

  • ?attr/textAppearanceTitleMedium for headings
  • ?attr/textAppearanceBodyMedium for body text
  • Always use theme attributes, not hardcoded sizes

Snackbar vs Toast:
Snackbar = interactive, swipeable, supports actions
Toast = non-interactive, auto-dismiss, avoid in modern apps