【问题标题】:Fading the toolbar text color on collapse折叠时淡出工具栏文本颜色
【发布时间】:2018-07-17 09:15:19
【问题描述】:

我正在使用 CollapsingToolbarLayout 来创建可折叠工具栏。 背景图片按预期淡化为工具栏颜色。 现在,我还想在工具栏标题和副标题折叠时淡化它的文本颜色(从黑色到白色)。 没有 OnOffsetChangedListener 是否有可能做到这一点?

<android.support.design.widget.AppBarLayout
    android:id="@+id/layout_bar"
    android:layout_width="match_parent"
    android:layout_height="210dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:titleEnabled="true">

        <ImageView
            android:id="@+id/fadingImage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_collapseMode="pin"
            app:navigationIcon="@drawable/ic_arrow_back">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Information"
                    android:textColor="@android:color/black"
                    android:textSize="24sp" />

                <TextView
                    android:id="@+id/subtitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/title"
                    android:fontFamily="sans-serif-light"
                    android:text="Message List"
                    android:textSize="17sp" />

            </RelativeLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

【问题讨论】:

  • 看看this
  • 我将如何在 OnOffsetChangedListener 中使用颜色淡入/更改为较暗的色调来执行此操作?谢谢

标签: android android-layout


【解决方案1】:

设置标题展开和折叠样式:

mCollapsingToolbarLayout.setTitle(getTitle());
mCollapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.AppBarExpanded);
mCollapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.AppBarCollapsed);

样式应如下所示:

<style name="AppBarCollapsed" parent="@android:style/TextAppearance.Medium">
    <item name="android:textSize">32sp</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textStyle">normal</item>
</style>

<style name="AppBarExpanded" parent="@android:style/TextAppearance.Medium">
    <item name="android:textSize">16sp</item>
    <item name="android:textColor">@color/black</item>
    <item name="android:textStyle">normal</item>
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多