Material 3 Floating Toolbars in Android with Developer Documentation

Material 3 Floating Toolbars

Overview

Floating Toolbars display page-specific actions in a flexible, undocked layout.

Overview of Material 3 Floating Toolbar

Material 3 Floating Toolbars, using FloatingToolbarLayout and OverflowLinearLayout, support horizontal or vertical orientations with hide-on-scroll and overflow menu capabilities. They can be paired with FABs for enhanced flexibility. This guide covers implementation, accessibility, and theming.

Getting Started

  • Add Material Components for Android library dependency
  • Use FloatingToolbarLayout with OverflowLinearLayout
  • Apply Theme.Material3.* for styling
  • Enable Material3Expressive themes for expressive styles

Accessibility

  • Set android:contentDescription on actions for TalkBack
  • Use accessibilityTraversalBefore/After for focus order
  • Disable hide-on-scroll for TalkBack with padding adjustments

Behavior and Configuration

  • Enable hide-on-scroll with HideViewOnScrollBehavior
  • Use OverflowLinearLayout for overflow menus
  • Support horizontal or vertical orientations
      
val boldButton = findViewById<Button>(R.id.floating_toolbar_button_bold)
val italicButton = findViewById<Button>(R.id.floating_toolbar_button_italic)
boldButton.setOnClickListener { /* Handle bold */ }
italicButton.setOnClickListener { /* Handle italic */ }
val overflowLayout = findViewById<com.google.android.material.overflow.OverflowLinearLayout>(R.id.floating_toolbar_child)
overflowLayout.getOverflowedViews().forEach { view ->
    view.setOnClickListener { /* Handle overflow item click */ }
}
      
    

Expressive Update

Floating Toolbar expressive style
  • Supports horizontal and vertical layouts
  • Standard or vibrant color options
  • Flexible positioning, can pair with FAB

Floating Toolbar Anatomy

Floating Toolbar anatomy
Component Description Behavior
Container FloatingToolbarLayout, colorSurfaceContainer or colorPrimaryContainer Flexible positioning, supports hide-on-scroll
Content Icon buttons or custom views in OverflowLinearLayout Triggers actions, supports overflow menu

Floating Toolbar Example

Horizontal Floating Toolbar example
  • Supports icon buttons and overflow menus
  • Configurable with horizontal or vertical orientation

Example

      
<androidx.coordinatorlayout.widget.CoordinatorLayout
    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">
    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/content"
            android:accessibilityTraversalAfter="@id/floating_toolbar"/>
    </androidx.core.widget.NestedScrollView>
    <com.google.android.material.floatingtoolbar.FloatingToolbarLayout
        android:id="@+id/floating_toolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:layout_margin="16dp"
        android:accessibilityTraversalBefore="@id/content"
        app:layout_behavior="com.google.android.material.behavior.HideViewOnScrollBehavior">
        <com.google.android.material.overflow.OverflowLinearLayout
            android:id="@+id/floating_toolbar_child"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal">
            <Button
                android:id="@+id/floating_toolbar_button_bold"
                style="?attr/materialIconButtonFilledStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checkable="true"
                android:contentDescription="@string/bold"
                app:icon="@drawable/ic_format_bold_24"
                app:layout_overflowText="@string/bold"
                app:layout_overflowIcon="@drawable/ic_format_bold_24"/>
            <Button
                android:id="@+id/floating_toolbar_button_italic"
                style="?attr/materialIconButtonFilledStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checkable="true"
                android:contentDescription="@string/italic"
                app:icon="@drawable/ic_format_italic_24"
                app:layout_overflowText="@string/italic"
                app:layout_overflowIcon="@drawable/ic_format_italic_24"/>
        </com.google.android.material.overflow.OverflowLinearLayout>
    </com.google.android.material.floatingtoolbar.FloatingToolbarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
      
    
      
val boldButton = findViewById<Button>(R.id.floating_toolbar_button_bold)
val italicButton = findViewById<Button>(R.id.floating_toolbar_button_italic)
boldButton.setOnClickListener { /* Handle bold */ }
italicButton.setOnClickListener { /* Handle italic */ }
val overflowLayout = findViewById<com.google.android.material.overflow.OverflowLinearLayout>(R.id.floating_toolbar_child)
overflowLayout.getOverflowedViews().forEach { view ->
    view.setOnClickListener { /* Handle overflow item click */ }
}
      
    

Attributes and Usage

Element Attribute Related Method(s) Default Value Usage Description
Container app:backgroundTint N/A Standard: ?attr/colorSurfaceContainer, Vibrant: ?attr/colorPrimaryContainer Sets toolbar background color
Container app:shapeAppearance N/A 50% rounded Sets toolbar corner shape
Container app:marginBottomSystemWindowInsets N/A true Applies system inset margin
Behavior app:layout_behavior N/A null Enables hide-on-scroll

Theming Floating Toolbars

Themed Floating Toolbar
  • Customize color and typography
  • Use res/values/styles.xml or vibrant style

Example

      
<style name="Theme.App" parent="Theme.Material3.*">
    <item name="colorPrimary">@color/shrine_theme_light_primary</item>
    <item name="colorSurface">@color/shrine_theme_light_surface</item>
</style>
      
    
      
<style name="Theme.App" parent="Theme.Material3.*">
    <item name="floatingToolbarStyle">@style/Widget.App.FloatingToolbar</item>
</style>
<style name="Widget.App.FloatingToolbar" parent="Widget.Material3.FloatingToolbar">
    <item name="materialThemeOverlay">@style/ThemeOverlay.App.FloatingToolbar</item>
</style>
<style name="ThemeOverlay.App.FloatingToolbar" parent="">
    <item name="colorPrimary">@color/shrine_theme_light_primary</item>
    <item name="colorSurface">@color/shrine_theme_light_surface</item>
</style>
      
    
      
<com.google.android.material.floatingtoolbar.FloatingToolbarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    style="@style/Widget.App.FloatingToolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center"
    android:layout_margin="16dp"
    app:layout_behavior="com.google.android.material.behavior.HideViewOnScrollBehavior"/>
      
    

Orientation Comparison

Orientation Pros Cons Image
Horizontal
  • Compact for multiple actions
  • Suitable for bottom or top placement
  • May overflow on narrow screens
Horizontal Floating Toolbar
Vertical
  • Ideal for side placement
  • Less screen width impact
  • Limited to fewer actions
Vertical Floating Toolbar

Material Design Documentation

  • Adheres to Material Design guidelines for Floating Toolbars
  • Covers design, behavior, theming specifications
  • Includes accessibility and orientation support
  • Refer to Material Design documentation for full details

FAQ

What is a Material 3 Floating Toolbar?

  • Undocked toolbar for page-specific actions

How does it differ from Docked Toolbar?

  • Flexible positioning vs. fixed bottom alignment

When to use a Floating Toolbar?

  • Use for actions needing flexible placement or overflow menus

How to make it accessible?

  • Set contentDescription; manage focus order

Can I customize its appearance?

  • Yes, theme via res/values/styles.xml

How to add the Material 3 library?

  • Include Material Components for Android library

Are there updates for the latest standards?

  • Reflects latest Material 3 standards for Floating Toolbars

Post a Comment

Previous Post Next Post