用scrollview更改工具栏文本颜色

问题描述 投票:0回答:1

我正在尝试使用scroll来设置CollapsingToolbarLayout标题的动画。我的目标是为文本中心位置设置动画,现在将文本设置为动画左侧。这是我的xml代码

我的目标是接收这样的结果。我想用中心大小的工具栏文本更改CollapsingToolbarLayout文本,我也会用滚动位置更改工具栏背景颜色。

我怎么能解决这个问题?谢谢

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="321dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleGravity="bottom|center_horizontal"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/imageViewCollapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/winterscenery"
            app:layout_collapseMode="parallax" />

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

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

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


<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/content_text_one" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/content_button" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/content_text_two" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

android android-scrollview android-coordinatorlayout
1个回答
0
投票

尝试使用CollapsingToolbarLayout中的任何更改..制作样式..

<style name="coll_toolbar_title">
    <item name="android:textColor">@color/primary</item>
    <item name="android:textSize">@dimen/_13sdp</item>
</style>

然后设置..使用id ..

collapseLayout.setCollapsedTitleTextAppearance(R.style.coll_toolbar_title)

mange滚动更改此处可以更改工具栏背景...

appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    boolean isShow = true;
    int scrollRange = -1;

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (scrollRange == -1) {

        }
        if (scrollRange + verticalOffset == 0) {
            // expend
            collapsingToolbarLayout.setTitle("Title");
            isShow = true;
        } else if(isShow) {
            // collepse
            collapsingToolbarLayout.setTitle(" ");//carefull there should a space between double quote otherwise it wont work 
            isShow = false;
        }
    }
});
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.