How to get ExtendedFloatingActionButton to behave similar to FloatingActionButton when interacting with CoordinatorLayout and scrolling?

582 views Asked by At

Trying to use the new ExtendedFloatingActionButton. It seems by default ExtendedFloatingActionButton acts differently from FloatingActionButton when interacting with CoordinatorLayout. See here the red one is the typical FloatingActionButton and the 2 black ones are the ExtendedFloatingActionButton with exactly the same setup (except for colors and text). What I need is for the black ones to hide away just like the red one does.

Text

Here's the layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_scrolling" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:theme="@style/Theme.MaterialComponents.NoActionBar"
        android:id="@+id/exfab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|start"
        app:strokeColor="#ffff00"
        app:strokeWidth="4dp"
        app:iconTint="#ffff00"
        android:text="txt"
        android:textColor="#ffff00"
        android:backgroundTint="#000000"
        app:icon="@android:drawable/ic_dialog_email" />

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:theme="@style/Theme.MaterialComponents.NoActionBar"
        android:id="@+id/exfab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|center"
        app:strokeColor="#ffff00"
        app:strokeWidth="4dp"
        app:iconTint="#ffff00"
        android:textColor="#ffff00"
        android:backgroundTint="#000000"
        app:icon="@android:drawable/ic_dialog_email" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I see in source that there's a nested class ExtendedFloatingActionButton.ExtendedFloatingActionButtonBehavior and it seems to have maybe some properties that might be useful/related to this such as autoHideEnabled and autoShrinkEnabled but the class is protected and I can't figure out how it is meant to be accessed. Please help.

0

There are 0 answers