Skip to content

Instantly share code, notes, and snippets.

@thanhit93
Created July 21, 2018 02:48
Show Gist options
  • Save thanhit93/65b0618f8e86738c55bbc3fa3701362b to your computer and use it in GitHub Desktop.
Save thanhit93/65b0618f8e86738c55bbc3fa3701362b to your computer and use it in GitHub Desktop.
AppBar Layout
It doesn't look like there's anything in the APIs, but the following seems to be working for me. It might need testing.
boolean fullyExpanded =
(appBarLayout.getHeight() - appBarLayout.getBottom()) == 0;
Edit: The above solution does seem to work, but since I wanted to test this condition when the appbar was scrolled, I ended up using the following solution with OnOffsetChangedListener.
class Frag extends Fragment implements AppBarLayout.OnOffsetChangedListener {
private boolean appBarIsExpanded = true;
private AppBarLayout appBarLayout;
@Override
public void onActivityCreated(Bundle state) {
super.onActivityCreated(state);
appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.app_bar);
}
@Override
public void onResume() {
super.onResume();
appBarLayout.addOnOffsetChangedListener(this);
}
@Override
public void onStop() {
super.onStop();
appBarLayout.removeOnOffsetChangedListener(this);
}
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
appBarIsExpanded = (verticalOffset == 0);
}
}
source :https://stackoverflow.com/questions/32213783/detecting-when-appbarlayout-collapsingtoolbarlayout-is-completely-expanded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment