Hide floating button when collapsing toolbar is collapsed

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)
     })

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


Try this small change

<android.support.design.widget.FloatingActionButton
    ...
    app:layout_anchor="@id/appBar"
    app:layout_anchorGravity="bottom|right|end" />