I am trying to hide my FloatingActionButton fabLocation programmatically with :
fabLocation.setVisibility(View.GONE)
but it do
The real solution for your problem is to subclass default FloatingActionButton.Behavior to call setAutoHide(false) in their constructors, so you can control it yourself.
Note that I talk about bottom sheets below, but it is exactly the same problem for all anchored Floating Action Buttons, and it does respond to the question and should solve the problem as expected.
Alternatively, you can override the boolean onDependentViewChanged(…) method from your custom Behavior, copy the isBottomSheet(…) static method present in the FloatingActionButton.Behavior class, and only call & return the value of the super method if it's not a bottom sheet.
You can further customize the default behavior this way, or by extending the vanilla CoordinatorLayout.Behavior class directly, and you can cherry pick code to copy paste from the FloatingActionButton.Behavior class if needed.
Here's the code I used to control back the FAB visibility:
/**
* Allows controlling the FAB visibility manually.
*/
@SuppressWarnings("unused")
public class FabManualHideBehavior extends FloatingActionButton.Behavior {
public FabManualHideBehavior() {
super();
setAutoHideEnabled(false);
}
public FabManualHideBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
setAutoHideEnabled(false);
}
}
And I applied it to my FAB in xml this way:
...