Auto-Hide or Auto-Extend Floating Action Button for NestedScrollView in Android
Last Updated : 23 Jul, 2025
In the previous article Extended Floating Action Button in Android with Example it's been discussed how to implement the Extended Floating Action Button (FAB) in Android and more of its functionalities. In this article it's been discussed it's one of the features to auto-hide or auto-extend the Floating Action Button in Android. Have a look at the following image on what things are discussed in this article. In this article, the nested scroll view is used.
Steps to Implement auto-hide or auto-extend Floating Action Button
Step 1: Create an empty activity project
Create an empty activity in Android studio. And select Java as a programming language.
Step 5: Now working with the MainActivity.java file
There is a need to handle the NestedScrollView with OnScrollChangeListener. If the NestedScrollView is scrolled down then the ExtendedFloatingAction button should be shrink state, and when scrolled up the FAB should be in an extended state.
Invoke the following code to implement the functionality. Comments are added for better understanding.
Output: Run on Emulator
Now replacing the Extended Floating Action button with normal Floating Action Button
Replace the Extended Floating Action Button with Normal Floating Action Button to hide the FAB when scrolled down, and it FAB should appear when scrolled up.
Invoke the following code inside the activity_main.xml file. Here the Extended FAB is replaced with the normal FAB.