12

The setTitle() method from CollapsingToolbarLayout had some bugs already (like showing only after a scroll, fixed in v22.2.1).

Today I updated to v23.0.0, and it is simply not working, like no title is shown. By calling it multiple times with a delay, I can see that sometimes the title is there, but it is really not reliable (like, you switch to another fragment, then back to the first, and there's no title anymore).

I found there's a new attribute, app:titleEnabled or CollapsingToolbarLayout.setTitleEnabled(boolean). I have set both to true, but it doesn't change anything actually.

Is any of you experiencing the same behavior?

I wonder how many apps out there in the market are really using this Design Library, it has been full of bugs from the very first release and is not getting better.

Edit

With further testing, it seems (I'm not 100% sure) it is connected to the new AppBarLayout.setExpanded() api.

If I call:

collapsingToolbar.setTitle("title");

it works, but if I call

collapsingToolbar.setTitle("title");
appbarLayout.setExpanded(true, true);
//OR
appbarLayout.setExpanded(true, true);
collapsingToolbar.setTitle("title");

it doesn't - no title shown. Same with setExpanded(false, true), i. e. trying to collapse the toolbar.

Edit2 (sep 2015)

Well, no. The issue is present even when I never call abl.setExpanded() or app:expanded. Also, we're on v23.0.1 now and this still has not been fixed. Looks like only a few of us are experiencing it, because I couldn't find anything here nor in the official bug list. I filed a bug here.

natario
  • 24,954
  • 17
  • 88
  • 158
  • Hi, I or anyone else might be able to help you if you'd post related code here (Java and XML). I've been using CollapsingToolbarLayout without any trouble so far. – Luboš Staráček Aug 18 '15 at 13:47
  • I am experiencing this problem using 24.0.1 CoordinatorLayout should be disbanded from the general design metaphor. Its pain in the fvcking a$$ to work with. Its been 3 years I've been deving in android and I couldn't understand this POS. – Neon Warge Sep 24 '16 at 07:00

2 Answers2

5

The title doesn't show because the layout height of the AppBarLayout is too small. I had a height of 110dp and this worked in v22.2.1. After I upgraded to v23.0.0, I had to change the height to at least 125dp in order for the title to show. No need to use the new attribute or method calls. Here is my layout:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="125dp"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:expandedTitleTextAppearance="@style/ExpandedAppBarTitle"
        app:expandedTitleMarginStart="14dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"/>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView android:id="@android:id/list"
                                        xmlns:android="http://schemas.android.com/apk/res/android"
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/addbtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    app:borderWidth="0dp"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add" />

hfann
  • 599
  • 3
  • 13
3

I've tried some combinations in my app:

collapsingToolbar.setTitle("title");
appbarLayout.setExpanded(true, true); // works

collapsingToolbar.setTitle("title");
appbarLayout.setExpanded(true, false); // works

collapsingToolbar.setTitle("title");
appbarLayout.setExpanded(false, true); // works

collapsingToolbar.setTitle("title");
appbarLayout.setExpanded(false, false); // doesn't show title

I've called these methods in onCreateView() in my fragment. AppBarLayout is expanded by default, which can be changed via XML in your layout, although when I define it to not be expanded in XML, it doesn't show title as well. Weird stuff... anyway, if you'd have some idea how could I help further, let me know.

  • I'm not sure anymore that it's linked to setExpanded. I have tried just using collapsingToolbar.setTitle("title"); and it works, like, 9 times over 10 (which is not good). – natario Aug 19 '15 at 10:39
  • Adding "true" to the animation fixes it, apparently.. sounds to me like it's due to the collapsing messing up the z-index of the title/toolbar element and going on top of it, while the animation forces everything to be drawn in the correct order... either way, great find, I'm using this in my app as well now – Mdk Sep 17 '15 at 20:42
  • Update: setting `app:expanded="false"` in the xml makes the title invisible unless you expand and re-collapse the element programatically... which sucks – Mdk Sep 17 '15 at 22:40
  • @Mdk : I have filed an issue here: https://code.google.com/p/android/issues/detail?id=186986&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars – natario Sep 19 '15 at 11:44
  • Note that I get this issue even when *never* using `app:expanded` or `abl.setExpanded()`. I agree with the z-index stuff. – natario Sep 19 '15 at 11:51