Created
August 21, 2019 06:55
-
-
Save ELTEGANI/75569a940e15e6d2cf3afd734ad94e4e to your computer and use it in GitHub Desktop.
Show CollapsibleToolbar title only when Toolbar is collapsed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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