F.A.B Hides But Doesn't Show
Solution 1:
Which support library version are you using in your project?
If you are using the latest one ( I mean 25.0.x), this is because fab.hide() method set the visibility to be View.GONE. This makes nested scroll listener stop to check fab, the second time you try to scroll the list.
More detail can be found here: https://code.google.com/p/android/issues/detail?id=230298
And I search a bit found this similar question already have a nice answer: Floating action button not visible on scrolling after updating Google Support & Design Library
So a possible work around would be to override fab.hide method, not to set the visibility to GONE but INVISIBLE instead.
And I think this may be fixed from upstream later, so just keep an eye on it.
Solution 2:
Because the update of Android to 25.0.x+ you should set the fab button with the listener to INVISBLE to show again the fab button, my solution is the next:
public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
private static final String TAG = "ScrollAwareFABBehavior";
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
super();
}
@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View directTargetChild, @NonNull View target, int axes, int type) {
return true;
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
if(dependency instanceof RecyclerView)
return true;
return false;
}
@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type);
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
@Override
public void onHidden(FloatingActionButton fab) {
super.onHidden(fab);
fab.setVisibility(View.INVISIBLE);
}
}
);
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
child.show();
}
}
}
** Tested in a Nexus 6P with Android Oreo.
Solution 3:
Use double check methods as suggested before. A fab can be showed and invisible at the same time, so for flawless showing fab:
fab.show(); fab.setVisibility(View.VISIBLE);
Post a Comment for "F.A.B Hides But Doesn't Show"