CollapsingToolbarLayout.setTitle(title) does not work after changing appbarLayout
<p>I want to load a fragment with the collapsed collapsingToolbar (i.e. in its non-expanded form). When I set the title of the collapsingToolbar without altering the appbarLayout layout parameters, the title is set properly and I can see the title.</p>
<p>The problem is, I also need to alter the appBarLayout layout parameters to prevent the collapsingToolbar from expanding (i.e. I want it to look and behave like a regular non-collapsing toolbar for this particular fragment). However, doing so makes the title no longer appear.</p>
<p><strong>What I've tried:</strong>
I've tried solutions listed at these pages to no avail:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/32073812/collapsingtoolbarlayout-settitle-not-working-anymore">CollapsingToolbarLayout setTitle() not working anymore</a></li>
<li><a href="https://stackoverflow.com/questions/30682548/collapsingtoolbarlayout-settitle-does-not-update-unless-collapsed">CollapsingToolbarLayout setTitle() does not update unless collapsed</a></li>
<li><code>collapsingToolbarLayout.setTitleEnabled(true);</code> doesn't seem to have any effect</li>
</ul>
<p><strong>MainActivity.java</strong>
I believe I have isolated the problem to these lines, but I am not sure how to solve it.</p>
<pre class="lang-java prettyprint-override"><code>collapsingToolbarLayout.setTitle(&quot;All Recent&quot;); // works
appBarLayout.setExpanded(false, true); // works

// However, after adding the following lines, the above no longer works and the title does not appear in the toolbar
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams)appBarLayout.getLayoutParams();
lp.height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80, getResources().getDisplayMetrics());
appBarLayout.setLayoutParams(lp);
</code></pre>
<p><strong>activity_main.xml</strong></p>
<pre><code>&lt;!-- language: lang-xml --&gt;

    &lt;android.support.design.widget.CoordinatorLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    android:id=&quot;@+id/coordinator_layout&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:fitsSystemWindows=&quot;true&quot;&gt;

    &lt;android.support.design.widget.AppBarLayout
        android:id=&quot;@+id/appbar_layout&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;@dimen/detail_backdrop_height&quot;
        android:fitsSystemWindows=&quot;true&quot;
        android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot;&gt;

        &lt;android.support.design.widget.CollapsingToolbarLayout
            android:id=&quot;@+id/collapsing_toolbar&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            android:fitsSystemWindows=&quot;true&quot;
            app:contentScrim=&quot;?attr/colorPrimary&quot;
            app:expandedTitleMarginEnd=&quot;64dp&quot;
            app:expandedTitleMarginStart=&quot;48dp&quot;
            app:layout_scrollFlags=&quot;scroll|exitUntilCollapsed&quot;&gt;

            &lt;ImageView
                android:id=&quot;@+id/backdrop&quot;
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;match_parent&quot;
                android:fitsSystemWindows=&quot;true&quot;
                android:scaleType=&quot;centerCrop&quot;
                app:layout_collapseMode=&quot;parallax&quot;
                android:adjustViewBounds=&quot;true&quot; /&gt;

            &lt;android.support.v7.widget.Toolbar
                android:id=&quot;@+id/toolbar&quot;
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;?attr/actionBarSize&quot;
                app:layout_collapseMode=&quot;pin&quot;
                android:minHeight=&quot;?attr/actionBarSize&quot;
                app:popupTheme=&quot;@style/ThemeOverlay.AppCompat.Light&quot;
                app:title=&quot;@string/drawer_item_locate_events&quot; /&gt;

        &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;

    &lt;/android.support.design.widget.AppBarLayout&gt;

    &lt;android.support.v4.widget.NestedScrollView
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        android:layout_gravity=&quot;fill_vertical&quot;
        android:fillViewport=&quot;true&quot;
        app:layout_behavior=&quot;@string/appbar_scrolling_view_behavior&quot;&gt;

        &lt;FrameLayout
            android:id=&quot;@+id/frame_fragments&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot; /&gt;

    &lt;/android.support.v4.widget.NestedScrollView&gt;

    &lt;android.support.design.widget.FloatingActionButton
        android:id=&quot;@+id/floating_action_button&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:layout_margin=&quot;@dimen/fab_margin&quot;
        android:clickable=&quot;true&quot;
        android:src=&quot;@mipmap/ic_add_a_photo&quot;
        app:layout_anchor=&quot;@+id/appbar_layout&quot;
        app:layout_anchorGravity=&quot;bottom|right|end&quot; /&gt;
&lt;/android.support.design.widget.CoordinatorLayout&gt;
</code></pre>
<p>Title no longer shows after altering appbarLayout's parameters</p>
<p><a href="https://i.stack.imgur.com/C4CsN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C4CsN.png" alt="Title no longer shows after altering appbarLayout's parameters" /></a></p>