FloatingActionButton doesn't hide

后端 未结 17 945
星月不相逢
星月不相逢 2020-11-30 03:42

I am trying to hide my FloatingActionButton fabLocation programmatically with :

fabLocation.setVisibility(View.GONE)

but it do

17条回答
  •  庸人自扰
    2020-11-30 04:10

    FloatingActionButtons anchored to AppBarLayouts have a special relationship where their visibility is controlled by the scroll position of the AppBarLayout.

    You can turn this off via the behavior_autoHide attribute:

    
    

    You can also do this programmatically if you wish:

    EDIT:

    fab.getBehavior() was not correct, use getBehavior() from its LayoutParams

    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
    FloatingActionButton.Behavior behavior = (FloatingActionButton.Behavior) lp.getBehavior();
    if (behavior != null) {
        behavior.setAutoHideEnabled(false);
    } else {
        behavior = new FloatingActionButton.Behavior();
        behavior.setAutoHideEnabled(false);
        lp.setBehavior(behavior);
    }
    

提交回复
热议问题