Skip to content

Instantly share code, notes, and snippets.

@ELTEGANI
Created August 21, 2019 06:55
Show Gist options
  • Save ELTEGANI/75569a940e15e6d2cf3afd734ad94e4e to your computer and use it in GitHub Desktop.
Save ELTEGANI/75569a940e15e6d2cf3afd734ad94e4e 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