Search code examples
androidandroid-design-libraryandroid-collapsingtoolbarlayout

How can I determine that CollapsingToolbar is collapsed?


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


Solution

  • UPDATE: Since support versions of 23.1.1+ the issue is no longer there, no need to use the listener and disable the swipe refresh layout, it will work as it should (link).


    Implement AppBarLayout.OnOffsetChangedListener listener on your AppBarLayout

    AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar_layout);
    appBarLayout.addOnOffsetChangedListener(this);
    

    And check if offset is 0, meaning the toolbar is fully expanded.

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int offset)
    {
        if (offset == 0)
        {
            // Fully expanded
        }
        else
        {
            // Not fully expanded or collapsed
        }
    }