Skip to content

Instantly share code, notes, and snippets.

@quevon24
Created May 7, 2018 21:51
Show Gist options
  • Save quevon24/987e04e0cb3a44adbf1f6538fae429b6 to your computer and use it in GitHub Desktop.
Save quevon24/987e04e0cb3a44adbf1f6538fae429b6 to your computer and use it in GitHub Desktop.
Show CollapsibleToolbar title only when Toolbar is collapsed.
// From - http://stackoverflow.com/a/32724422/906577
...
final CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) mRootView.findViewById(R.id.collapsing_toolbar);
AppBarLayout appBarLayout = (AppBarLayout) mRootView.findViewById(R.id.appbar);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean isShow = false;
int scrollRange = -1;
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
collapsingToolbar.setTitle(title);
isShow = true;
} else if (isShow) {
collapsingToolbar.setTitle("");
isShow = false;
}
}
});
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment