Skip to content

Instantly share code, notes, and snippets.

@jaredsburrows
Created March 7, 2016 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredsburrows/e673a28e7713040393c5 to your computer and use it in GitHub Desktop.
Save jaredsburrows/e673a28e7713040393c5 to your computer and use it in GitHub Desktop.
Hide/Show Fab
final OnVisibilityChangedListener searchVisibilityChangedListener = new OnVisibilityChangedListener() {
@Override
public void onShown(final FloatingActionButton fab) {
super.onShown(fab);
}
@Override
public void onHidden(final FloatingActionButton fab) {
super.onHidden(fab);
floatingActionButton.setImageResource(R.drawable.ic_search_white_24dp);
floatingActionButton.show();
}
};
final OnVisibilityChangedListener editVisibilityChangedListener = new OnVisibilityChangedListener() {
@Override
public void onShown(final FloatingActionButton fab) {
super.onShown(fab);
}
@Override
public void onHidden(final FloatingActionButton fab) {
super.onHidden(fab);
floatingActionButton.setImageResource(R.drawable.ic_edit_white_24dp);
floatingActionButton.show();
}
};
@Override
public void onPageSelected(final int position) {
if (position == FRAGMENT_POSITION_ONE) {
this.floatingActionButton.hide(searchVisibilityChangedListener);
} else if (position == FRAGMENT_POSITION_TWO) {
this.floatingActionButton.hide(editVisibilityChangedListener);
} else {
this.floatingActionButton.hide(addVisibilityChangedListener);
}
this.currentPage = position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment