从我的CollapsingToolbarLayout更改颜色 [英] Change color from my CollapsingToolbarLayout

查看:141
本文介绍了从我的CollapsingToolbarLayout更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据Material Design规则制作CollapsingToolbar动画。一切正常,但一件事情令我沮丧。滚动回收器视图时,我试图更改折叠的工具栏的颜色,但是获得的透明颜色始终相同...

I am trying to do a CollapsingToolbar animation based in Material Design rules. Everything works well but a thing that is breaking down my mind. I am trying to change the color of my Collapsed tool bar when scroll my recycler view, but the transparent color that I get is allways the same...

这是我的xml代码:

<android.support.design.widget.AppBarLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="256dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            android:background="@color/gps_friends_green_main"
            app:contentScrim="@color/gps_friends_green_main"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">
            <ImageView
                android:id="@+id/imgHeader"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolBarDetalleContacto"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/MyNavigationDrawerTheme"
                app:layout_collapseMode="pin">
                </android.support.v7.widget.Toolbar>

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

这是我的Java代码

int mutedColor = R.color.gps_friends_green_main;

    Palette.generateAsync(bitmap,
                    new Palette.PaletteAsyncListener() {
                        @Override
                        public void onGenerated(Palette palette) {
                            Palette.Swatch vibrant =
                                    palette.getVibrantSwatch();

                            if (vibrant != null) {
                                // If we have a vibrant color
                                // update the title TextView
                                collapseToolbar.setBackgroundColor(mutedColor);
                                //  mutedColor = palette.getMutedColor(R.attr.colorPrimary);
                                collapseToolbar.setStatusBarScrimColor(palette.getDarkMutedColor(R.color.gps_friends_green_main));
                                collapseToolbar.setContentScrimColor(palette.getMutedColor(R.color.gps_friends_green_main));

                            }
                        }
                    });

其中gps_friend_main_color是<颜色名称= gps_friends_green_main>#1abc9c< ; / color>

Where gps_friend_main_color is <color name="gps_friends_green_main">#1abc9c</color>

这是我折叠的工具栏的结果:

This is the result of my collapsed toolbar:

我想更改这种深蓝色,但是我找不到解决方法。我有些绝望,但希望在这里找到答案。
谢谢。

I want to change this dark blue color but I don't find the way to do that. I am a bit desperate but hope to find the answer here. Thank you.

推荐答案

您更改颜色的代码是正确的。
您只需删除

Your code to change the color is correct. You just have to remove the

app:contentScrim = @ color / gps_friends_green_main

app:contentScrim="@color/gps_friends_green_main"

在您的 android.support.design.widget.CollapsingToolbarLayout中,它应该可以正常工作。

in your "android.support.design.widget.CollapsingToolbarLayout", and it should work.

这篇关于从我的CollapsingToolbarLayout更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆