2

I have this kind peace of xml.

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            app:toolbarId="@+id/toolbar"
            android:id="@+id/collapsing"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">


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

It shows no title at all. (picture below)

enter image description here

But when CollapsingToolbarLayout is a bit collapsed title shows.

enter image description here

i set activity title in on create method.

toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        CollapsingToolbarLayout layout = (CollapsingToolbarLayout) findViewById(R.id.collapsing);
        layout.setTitle(toolbar.getTitle());
        layout.invalidate();

full xml :

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


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


        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:paddingBottom="?attr/actionBarSize"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_height="match_parent"/>


        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           >



            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:minHeight="?attr/actionBarSize"
                android:fitsSystemWindows="true"
                app:toolbarId="@+id/toolbar"
                android:id="@+id/collapsing"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways">


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize" />


     </android.support.design.widget.CollapsingToolbarLayout>

            <LinearLayout
                android:id="@+id/custom_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="invisible"/>


        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>


    <LinearLayout
        android:id="@+id/drawer_linear"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:background="@color/drawer_grey"
            android:divider="@drawable/drawer_divider"
            android:scrollbars="none"
            android:dividerHeight="1px" />

    </LinearLayout>

Any ideas how to make Title show up always?

Alpha
  • 1,754
  • 3
  • 21
  • 39

2 Answers2

2

I've got the same problem and after hours of searching I found a solution and want to share it with you.

  1. Use com.android.support:design:23.1.0
  2. Your layout should look like this:

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
               <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_scrollFlags="scroll|enterAlways|snap />
    

I hope I can help somebody.

The solution is from this post.

Community
  • 1
  • 1
Lee
  • 819
  • 7
  • 32
  • This answer is downvoted, but it might be the right answer because `AppBarLayout` expects to be the first child of `CoordinatorLayout`. OP must be having issues because he/she has placed `FrameLayout` as the first child. – Ali Kazi Jul 28 '16 at 07:59
  • @AliKazi Yes, that's might be the case. – Alpha Sep 26 '16 at 11:34
1

You just need to add this to your theme in v-21 styles.xml.

<item name="android:windowTranslucentStatus">true</item>
NullByte
  • 165
  • 1
  • 6
  • doesn't solve the problem. I need that fully expanded toolbar would have title text. I don't need transparent status bar (not yet). – Alpha Jul 07 '15 at 08:58
  • well okey maybe it works,kind of. But still not quite the thing i'm looking for. since making app for ~4.0 and higher android. – Alpha Jul 07 '15 at 09:04
  • Its workaround for Lollipop, as your already using AppCompat so there wont be a problem on pre lollipop devices. – NullByte Jul 07 '15 at 09:11
  • 1
    @Alpha remove this android:fitsSystemWindows="true" from your CollapsingToolbarLayout. it will work fine. – NullByte Jul 08 '15 at 04:44
  • on 4.3 android not working at all. on 5.0.0 Toolbar goes below status bar and distorts. – Alpha Jul 08 '15 at 06:52
  • actually android:fitsSystemWindows="true" solved my problem yesterday, – NullByte Jul 08 '15 at 06:57
  • any way. you know how to force to show toolbar before on pause, or how to fix onResume Toolbar rendering bug? – Alpha Jul 08 '15 at 06:59