Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Collapsing)Toolbar title resets its position after Snackbar appearance

I have a layout with CollapsingToolbarLayout and CoordinatorLayout as root element. Whenever a Snackbar is shown in the activity the title of the toolbar resets its position to the default expanded title position of the CollapsingToolbar even if the toolbar is not (fully) expanded.

The second picture shows that the title is fixed no matter if the toolbar expands or not.

Fully expanded

After Snackbar was shown

The result is the same when I call snackbar.show() in activity or fragment.

My layout structure looks like this:

<CoordinatorLayout>
<AppBarLayout>
    <CollapsingToolbarLayout>
        <Toolbar />
        <TabLayout />
    </CollapsingToolbarLayout>
</AppBarLayout>
<ViewPager />
<FloatingActionButton />

I use the latest dependencies for appcompat and design library (v24.2.1). I hope that's enough information and somebody has an idea how to solve the issue :P

EDIT: Also in the template when you start a new project and choose Scrolling activity the same problem appears when snackbar.show()is called. So it's a library issue.

like image 317
Vkay Avatar asked Sep 23 '16 13:09

Vkay


People also ask

How do you collapse Appbarlayout?

Use mAppBarLayout. setExpanded(true) to expand Toolbar and use mAppBarLayout. setExpanded(false) to collapse Toolbar.

What is layout_collapseMode?

In addition to pinning a view, you can use app:layout_collapseMode="parallax" (and optionally app:layout_collapseParallaxMultiplier="0.7" to set the parallax multiplier) to implement parallax scrolling (say of a sibling ImageView within the CollapsingToolbarLayout ).


1 Answers

I was having the same problem and it was a library issue. On the latest version of design support library (25.0.0) is fixed. Use the following on your build.gradle:

compile 'com.android.support:design:25.0.0'

Hope this helps.

like image 195
Sol Avatar answered Oct 01 '22 23:10

Sol