Hide floating button when collapsing toolbar is collapsed

前端 未结 2 2353
长情又很酷
长情又很酷 2021-02-20 02:46

I have a coordinator layout containing a collapsing toolbar, a nestedscrollview and a floating button. My floating button is placed at the bottom right end of the collapsing too

2条回答
  •  北海茫月
    2021-02-20 03:15

    Setting offset listener to the toolbar would give you more flexibility: you'd be able to decide what would happen when the toolbar has collapsed / opened.

        appBarLayout.addOnOffsetChangedListener(
        AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
        if (verticalOffset == 0) {
            showFAB()
            // logic when toolbar is open (for example show fab)
         } else {
            hideFAB()
            // logic when toolbar has collapsed (for example hide fab)
         })
    

    If case you'd like to know whenever toolbar is in between / you need the java code: https://stackoverflow.com/a/39424318/11878751

提交回复
热议问题