How can I determine that CollapsingToolbar is collapsed?

d0pestar picture d0pestar · Aug 7, 2015 · Viewed 38.3k times · Source

I need to know when CollapsingToolbar from material design library is collapsed.

Answer

chrlaura picture chrlaura · Sep 10, 2016

As Marko said, this can be achieved using your own implementation of a OnOffsetChangedListener.

AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) {
                // Collapsed
            } else if (verticalOffset == 0) {
                // Expanded
            } else {
                // Somewhere in between
            }
        }
    }););