FloatingActionButton doesn't hide
It is due to the app:layout_anchor
attribute. You must get rid of the anchor before changing visibility:
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(View.NO_ID);
fab.setLayoutParams(p);
fab.setVisibility(View.GONE);
I can't hide Floating Action Button?
Use the method hide
:
fab.hide();
FloatingActionButton setVisibility() not working
If your issue is the animation, you could try invalidating the FAB Behavior
. As for the visibility, you should null the anchor you have set in your layout:
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setBehavior(null); //should disable default animations
p.setAnchorId(View.NO_ID); //should let you set visibility
fab.setLayoutParams(p);
fab.setVisibility(View.GONE); // View.INVISIBLE might also be worth trying
//to bring things back to normal state
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setBehavior(new FloatingActionButton.Behavior());
p.setAnchorId(R.id.appbar);
fab.setLayoutParams(p);
How to hide floatingActionButton when endDrawer is open Flutter
I think it's because you have the end drawer in the child Scaffold
, so the FloatingActionButton
is above the child Scaffold
including its endDrawer.
try moving the endDrawer to the parent Scaffold
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(),
drawer: Drawer(),
endDrawer: Drawer(),
body: Scaffold(
appBar: AppBar(),
body: Container(
),
),
);
or move the FloatingActionButton
to the child Scaffold
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(),
drawer: Drawer(),
body: Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(),
appBar: AppBar(),
endDrawer: Drawer(),
body: Container(
),
),
);
Custom auto hide floatingActionButton behavior is not working
Take a look at what @woxingxiao is saying here
Pretty much onNestedScroll
won't get fired if the visibility of the button is GONE
. So, replace:
child.hide();
to:
child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
@Override
public void onHidden(FloatingActionButton fab) {
super.onHidden(fab);
fab.setVisibility(View.INVISIBLE);
}
});
FloatingActionButton visible for sometime even if visibility is set to gone
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(View.NO_ID);
p.width = 0;
p.height = 0;
fab.setLayoutParams(p);
fab.setVisibility(View.GONE);
Floating Action Button attached with anchor not hiding when scrolling RecyclerView items slow
You have to implement custom behavior for FAB to achieve effect which you want.
I slightly changed original implementation, to get it working without toolbar.
public class FABBehavior extends FloatingActionButton.Behavior {
public FABBehavior() {
}
public FABBehavior(Context context, AttributeSet attributeSet) {
}
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
if(dependency instanceof Snackbar.SnackbarLayout) {
return super.onDependentViewChanged(parent, child, dependency);
} else if(dependency instanceof AppBarLayout) {
this.updateFabVisibility(parent, (AppBarLayout)dependency, child);
}
return false;
}
private boolean updateFabVisibility(CoordinatorLayout parent, AppBarLayout appBarLayout, FloatingActionButton child) {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams)child.getLayoutParams();
if(lp.getAnchorId() != appBarLayout.getId()) {
return false;
} else {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) child.getLayoutParams();
int point = child.getTop() - params.topMargin;
try {
Method method = AppBarLayout.class.getDeclaredMethod("getMinimumHeightForVisibleOverlappingContent");
method.setAccessible(true);
if(point <= (int) method.invoke(appBarLayout)) {
child.hide();
} else {
child.show();
}
return true;
} catch (Exception e) {
return true;
}
}
}
}
You may apply this behavior using app:layout_behavior
of course.
F.A.B Hides but Doesn't Show
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.
Related Topics
How Can Android Source Code Not Have a Main Method and Still Run
Stop Fragment Refresh in Bottom Nav Using Navhost
How to Get the Battery Level After Connect to the Ble Device
How to Add Parameters to API (Http Post) Using Okhttp Library in Android
Folder Added on Android Is Not Visible via Usb
Adding Multiple Markers in Google Maps API V2 Android
Firebase Authentication Not Working in Signed APK
How to Reduce the Spacing Between the Action Item Icons on Action Bar
Setting Android Theme Background Color
Sqlite Simultaneous Reading and Writing
Android:Dither="True" Does Not Dither, What's Wrong
Android: Changing Nfc Settings (On/Off) Programmatically
Pass Parameter with Volley Post
Genymotion Error After Windows 10 Upgrade
Android Emulator Screen Fills Up Only Some Fraction Part of Actual Android Emulator Screen