FloatingActionButton setVisibility() not working

后端 未结 6 1766
闹比i
闹比i 2021-02-07 07:13

I can\'t hide my FloatingActionButton. Here is my code:

XML:



    
         


        
6条回答
  •  离开以前
    2021-02-07 08:10

    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);
    

提交回复
热议问题