Collapsingtoolbarlayout Settitle() Not Working Anymore
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 work
Solution 1:
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.CoordinatorLayoutxmlns: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.AppBarLayoutandroid: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.CollapsingToolbarLayoutandroid: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.Toolbarandroid: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.RecyclerViewandroid: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.FloatingActionButtonandroid: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" />
Solution 2:
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.
Post a Comment for "Collapsingtoolbarlayout Settitle() Not Working Anymore"