Skip to content Skip to sidebar Skip to footer

Floating Action Button Not Visible On Scrolling After Updating Google Support & Design Library

I've tried updating com.android.support:appcompat and com.android.support:design from: 25.0.1 to 25.1.0, as follows: compile 'com.android.support:appcompat-v7:25.0.1' compile 'com.

Solution 1:

Updating from support lib 25.0.1 to 25.1.0 changes the onNestedScroll method of CoordinatorLayout in that the call is skipped for views whose visibility is set to View.GONE.

Calling child.hide() on the floating action button sets the view's visibility to View.GONE, which means now (as of 25.1.0), the onNestedScroll method call will be skipped for the floating action button in the future (because it skips all views whose visibility is GONE).

A workaround for this would be to set the view's visibility to INVISIBLE whenever you hide it. This way, the onNestedScroll will not skip the view the next time a nested scroll is performed.

In order to achieve this, you can call

child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
            /**
             * Called when a FloatingActionButton has been hidden
             *
             * @param fab the FloatingActionButton that was hidden.
             */@Override
            public void onHidden(FloatingActionButton fab) {
                super.onShown(fab);
                fab.setVisibility(View.INVISIBLE);
            }
        });

in your onNestedScroll method.

Edit: This issue has been submitted to the AOSP Issue Tracker at https://code.google.com/p/android/issues/detail?id=230298

Solution 2:

in CoordinatorLayout 25.1.0 (

for (inti=0; i < childCount; i++) {
            finalViewview= getChildAt(i);
            if (view.getVisibility() == GONE) {
                // If the child is GONE, skip...continue;
            }

in 25.0.1

for (inti=0; i < childCount; i++) {
            finalViewview= getChildAt(i);
            finalLayoutParamslp= (LayoutParams) view.getLayoutParams();
            if (!lp.isNestedScrollAccepted()) {
                continue;
            }

            finalBehaviorviewBehavior= lp.getBehavior();
            if (viewBehavior != null) {
                viewBehavior.onNestedScroll(this, view, target, dxConsumed, dyConsumed,
                        dxUnconsumed, dyUnconsumed);
                accepted = true;

        }

Solution 3:

The behavior has changed since support lib version 25.1.0.

It must be the RecyclerView (Behavior) that triggers the FAB visibility change.

In other words, it's no longer the responsibility of the object that wants to react to have a behavior but on the object that moves to be aware of everything on screen.

Below is a link to a diff that shows the changes that are required to perform the upgrade:

https://github.com/chrisbanes/cheesesquare/compare/master...ianhanniballake:scroll_aware_fab

Post a Comment for "Floating Action Button Not Visible On Scrolling After Updating Google Support & Design Library"