CollapsingToolbarLayout setTitle() does not update unless collapsed

EDIT: This solution is no longer needed. bug fixed in v22.2.1 I didnt want to just leave links so here is the full solution. The bug occurs because the code to handle the collapsable title only updates the actual title if the current title is null or the text size has changed. The workaround is … Read more

Android CollapsingToolbarLayout with custom View

I had the same problem and spend many hours trying to find a solution. My solution was to add the collapsing Views (ImageView and TextView) inside the CollapsingToolbarLayout and then handle the transition in code. This way it’s more flexible and simpler than extending from CollapsingToolbarLayout. First you’ll need to add your Views inside the … Read more

How to disable scrolling of AppBarLayout in CoordinatorLayout?

I’m not sure I got it, but I think you are looking for a DragCallback. The DragCallback interface allows to choose whether the sibling scrolling view should be controlled by scrolls onto the AppBarLayout. You can define one by calling: CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() { @Override public … Read more

How can I determine that CollapsingToolbar is collapsed?

As Marko said, this can be achieved using your own implementation of a OnOffsetChangedListener. AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar_layout); appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) { // Collapsed } else if (verticalOffset == 0) { // Expanded } else { // Somewhere in between } } … Read more

How to change CollapsingToolbarLayout typeface and size?

Update Before we dive into the code let’s first decide the textSize for our CollapsingToolbarLayout. Google published a website called material.io, this website also explains the best way on how to deal with Typography. The article mentioned about “Heading” category which also explains the recommended font size to use in sp. Although the article never … Read more

CollapsingToolbarLayout doesn’t recognize scroll fling

I had exactly the same issue with CollapsingToolbarLayout with ImageView inside and NestedScrollView. The fling scroll stops when finger is released. However, I’ve noticed something strange. If you start scrolling with your finger from a view with OnClickListener (e.g. Button), the fling scrolling works perfectly. Thus I fixed it with a weird solution. Set OnClickListener … Read more

Set starting height of CollapsingToolbarLayout

Actually AppBarLayout has special method to apply such offset: final int setAppBarTopBottomOffset(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, int newOffset, int minOffset, int maxOffset) Unfortunately it has package-private access level, but we can invoke it through such intermediate chain: private void setAppBarOffset(int offsetPx){ CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); behavior.onNestedPreScroll(mCoordinatorLayour, mAppBarLayout, null, 0, offsetPx, … Read more

Android CollapsingToolbarLayout collapse Listener

I share the full implementation, based on @Frodio Beggins and @Nifhel code: public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener { public enum State { EXPANDED, COLLAPSED, IDLE } private State mCurrentState = State.IDLE; @Override public final void onOffsetChanged(AppBarLayout appBarLayout, int i) { if (i == 0) { if (mCurrentState != State.EXPANDED) { onStateChanged(appBarLayout, State.EXPANDED); } mCurrentState … Read more

Error inflating class CollapsingToolbarLayout

I found a solution May it work try it: add below code in gradle build file compile (‘com.android.support:support-v4:23.4.0′){ force = true; } Seems like it is having version conflict issue. All support library must be of same version. However, I didn’t use v4 support library before and it works. I don’t know why updatimg android … Read more

Android: CollapsingToolbarLayout and SwipeRefreshLayout get stuck

Update: This issue has been resolved in the latest version of the support library (23.1.1+). If you are using an older version of the support library either upgrade or continue reading. If you’re using an older version of the support library, add an offset change listener to your AppBarLayout to enable or disable your swipe … Read more