I have an activity that has 3 tabs. Each tabs page is a fragment which displays a RecyclerView. One of the fragment has FloatingActionButton in it. I\'m implementing this Button
Add
app:layout_behavior="@string/appbar_scrolling_view_behavior"
to the RecyclerView too.
The best option would be to just put the FloatingActionButton in the Activity, and call show()
and hide()
in a ViewPager.OnPageChangeListener
. This way you get nice enter/exit animations that conform to Material Design guidelines.
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if (position == 0) {
fabAdd.show();
} else {
fabAdd.hide();
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Result: