【问题标题】:CollapsingToolbarLayout doesn't display title when there is no image没有图像时,CollapsingToolbarLayout 不显示标题
【发布时间】:2017-07-17 12:00:19
【问题描述】:

我正在使用 CollapsingToolbarLayout 在我的活动工具栏中显示图像,它工作正常。但有时,根据显示的片段,我不想显示任何图像。在这种情况下,我想要正常的工具栏。当我没有将任何可绘制对象传递给 imageView、将其高度设置为 0 或将其可见性设置为 GONE 时,工具栏看起来很正常,但没有标题。这是为什么呢?

我的布局文件:

<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" />

【问题讨论】:

    标签: android xml android-layout


    【解决方案1】:

    我猜在这种情况下你需要使用 CollapsingToolbar setTitleEnabled(false);link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多