Muhammad Arsal Muhammad Arsal - 1 month ago 18
Android Question

Hide and re-appear floating action button, android

I'm using floating action button in my android application. I've implemented a feature when a user scrolls down the list, FAB disappears. It appears back when a user scrolls up.

myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

if (dy >0) {
// Scroll Down
if (floatingActionButton.isShown()) {
floatingActionButton.hide();
}
}
else if (dy <0) {
// Scroll Up
if (!floatingActionButton.isShown()) {
floatingActionButton.show();
}
}
}
});


How to make FAB re-appear after 5 seconds even if the user doesn't scroll up?
If you're still not clear with my question, you can check this feature out in LinkedIn android application.

Answer

Use View.postDelayed() thread. For ex:

floatingActionButton.postDelayed(new Runnable() {
   @Override
   public void run() {
       floatingActionButton.show();
   }
},5000);
Comments