用平纹棉麻织物或颜色叠加更改标题的背景色CollapsingToolbarLayout [英] Change background color of title in CollapsingToolbarLayout using scrim or color overlay

查看:638
本文介绍了用平纹棉麻织物或颜色叠加更改标题的背景色CollapsingToolbarLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在处理的同时与更改标题的背景颜色在collapsingtoolbarlayout但仅扩大了的时候。为什么我想是不是有一个透明网布背景或颜色叠加(如文档说):

I have been dealing for a while now with changing the color of the background of the title in the collapsingtoolbarlayout but only when is expanded. Why I want is either have a transparent scrim background or a color overlay (like the documentation says):

在这里输入的形象描述

我想这种行为(或透明背景屏障也是可以的),事情是,我发现一模一样的问题,对这个职位:

I want this behaviour (or a protective screen with transparent background is also possible), the thing is I found exactly the same question on this post:

<一个href=\"http://stackoverflow.com/questions/31542878/android-collapsingtoolbarlayout-title-background/31838291#31838291\">Android CollapsingToolbarLayout标题背景

我申请这个解决我的Andr​​oid项目,但它没有工作,ImageView的后视图设置不显示(不知道为什么),但我没有在谷歌也不是没有(未找到文档)是如何管理一个颜色叠加做到这一点。

I've applied this solution to my android project but it didn't work, the view set after the imageView is not displaying (don't know why) but what I haven't found yet (not in google nor in the documentation) is how to manage to do this with a color overlay.

我要的是,当工具栏展开以显示标题后面的背景颜色,当它崩溃隐藏起来,只显示标题

What I want is that when the toolbar is expanded to show a color background behind the title and when it collapse hide it and only show the title

这是我到现在为止:

在这里输入的形象描述

正如你所看到的标题是很难读,取决于后面的ImageView的,所以我需要找到适合所有可能的图像解决方案。

As you see the title is very difficult to read and depends on the imageview that is behind, so I need to find a solution that fits all the possible images .

这是我的code:

在EstablecimientosDetail文件:

the EstablecimientosDetail file:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent i = getIntent();
        establecimiento = (HashMap<String, String>) i.getBundleExtra(TAG_ESTABLECIMIENTOS).getSerializable("Hashmap");

        setContentView(R.layout.activity_establecimientos_detalle);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_establecimiento_detalle);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        CollapsingToolbarLayout toolBarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
        toolBarLayout.setTitle(establecimiento.get(TAG_NOMBRE));
        toolBarLayout.setContentScrimColor(R.color.black_semi_transparent);
//        toolBarLayout.setCollapsedTitleTextColor(R.color.abc_primary_text_material_light);
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Llamando...", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        loadImage();
    }

    private void loadImage() {
        final ImageView imageView = (ImageView) findViewById(R.id.backdrop);
        Log.e("imagen actividad", establecimiento.get(TAG_IMAGEN_RECETA));
        Picasso.with(this).load(establecimiento.get(TAG_IMAGEN_RECETA)).error(R.drawable.logo_ternera_negro).into(imageView);
    }

相应的布局文件:

The corresponding layout file:


<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/Theme.TerneraGallega.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <!--<View-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="?attr/actionBarSize"-->
            <!--android:background="#000"-->
            <!--android:layout_gravity="bottom"/>-->

        <!--<View-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="@dimen/sheet_text_scrim_height_top"-->
            <!--android:background="@drawable/scrim_top"-->
            <!--app:layout_collapseMode="pin" />-->

        <View
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="bottom"
            android:background="@drawable/scrim_bottom" />

        <!--<include layout="@layout/toolbar" />-->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_establecimiento_detalle"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/EstablecimientosDetalleTheme" />

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

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_action_call"
    app:borderWidth="0dp"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end" />

和也的样式和绘制文件:

And also the styles and drawable files:

scrim_botton.xml

scrim_botton.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:startColor="@color/translucent_scrim_bottom"
        android:centerColor="@color/translucent_scrim_bottom_center"
        android:endColor="@android:color/transparent"/>
</shape>

styles.xml

styles.xml

    <style name="EstablecimientosDetalleTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="android:textColorPrimary">@color/abc_primary_text_material_light</item>

     <item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item>

    <item name="actionMenuTextColor">@color/abc_primary_text_material_light</item>

    <item name="android:textColorSecondary">@color/abc_secondary_text_material_light</item>

</style>

有谁知道如何实现这种行为?

Does anyone know how to achieve this behaviour?

在此先感谢

推荐答案

最后,我已经找到了解决方案。为了大家如何处理与CollapsingToolbarLayout和AppBarLayout麻布的观点,你必须设置最低程序兼容性支持库23的支持德兴+

Finally I have found the solution. To everyone how is dealing with scrim views with CollapsingToolbarLayout and AppBarLayout you have to set the minimum appcompat support library an support desing of 23+

以这一回答过的问题提供了有效的stackoverflow

The answered provided in this question is valid stackoverflow

但请注意设置build.grade的

But please be aware of setting the build.grade

compile 'com.android.support:design:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'

随着

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.irixgalicia.terneragallega"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

这篇关于用平纹棉麻织物或颜色叠加更改标题的背景色CollapsingToolbarLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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