Catching Event Collapsing Toolbar Android

Asked

Viewed 52 times

0

Is there any way to identify the Collapsingtoolbar Collapsing event?

Type one onChangeCollapsingListener

What I need to do is set the visibility of some screen components when the Collapsingtoolbar gives a expand or a Collapsing.

Thanks in advance.

1 answer

1

The AppBarLayout has a Switch to be notified of changes of offset.

I believe it is possible to be notified when it is completely collapsed or expanded as follows:

AppBarLayout.OnOffsetChangedListener  listener = new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if(collapsingToolbar.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
            // CollapsingToolbar esta colapsado
        } else {
            // CollapsingToolbar esta expandindo
        }
    }
};

appBar.addOnOffsetChangedListener(listener);

Source: https://stackoverflow.com/questions/31595741/show-view-when-toolbar-collapses

Browser other questions tagged

You are not signed in. Login or sign up in order to post.