1

I am using CollapsingToolbarLayout to display image in my activity's toolbar and it works fine. But sometimes, depending on displayed fragment, I don't want to display any image. In that case I would like normal looking toolbar. When I don't pass any drawable to imageView, set its height to 0, or set its visibility to GONE, the toolbar does look normal with exception that there is no title. Why is that?

My layout file:

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

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">
    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="40dp"
        android:background="@color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"                
            app:layout_collapseMode="parallax"/>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/transparent"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            />

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


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

<include layout="@layout/content_main" />

pgSystemTester
  • 8,979
  • 2
  • 23
  • 49
matip
  • 794
  • 3
  • 7
  • 27

1 Answers1

1

I guess in that case you need to use CollapsingToolbar setTitleEnabled(false); See link

Fatih Santalu
  • 4,641
  • 2
  • 17
  • 34