Search code examples
androidfloating-action-button

How to hide fab on clicking anywhere in screen?


I am using Floating Action Button. I am using this library because I needed inbox style fab. The problem is, I can close the floating action menu only on clicking the bottom fab. What I need is, if I click anywhere else on the screen, then also the fab should collapse as happens in Inbox app. How to achieve this behavior? Is there any attributes in this library that I can use or do I need to implement that behavior on my own?


Solution

  • The library has a method setClosedOnTouchOutside(boolean close) which you can use.

    floatingActionMenu.setClosedOnTouchOutside(true);
    

    But this will only be workable for floatingActionMenu's covered area. If you wanna close it by clicking anywhere in the layout then you should try this.