CollapsingToolBarLayout-状态栏稀松布颜色不变 [英] CollapsingToolBarLayout - status bar scrim color doesn't change

查看:82
本文介绍了CollapsingToolBarLayout-状态栏稀松布颜色不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我更新了android studio,并开始尝试使用CoordinatorLayout和CollapsingToolbarLayout.

I updated my android studio few days ago and started working with the CoordinatorLayout and CollapsingToolbarLayout just trying stuff.

似乎工具栏稀松布颜色会覆盖状态栏的初始颜色和状态栏稀松布的颜色(分别从xml和代码中进行尝试)

It seems that the Toolbar scrim colour override the status bar initial colour and the status bar scrim colour (tried both from xml and code)

初始状态:

开始滚动:

滚动直到崩溃:

所以问题是:

  1. 如何在折叠时防止工具栏覆盖状态栏(甚至不让折叠的图像上方).

  1. How can I prevent the toolbar to override the status bar when collapsing (not even letting the image I'm collapsing to go above it).

折叠后如何更改状态栏颜色

How can I change status bar colour after collapsing

我遇到的另一个问题是,我给工具栏指定了初始颜色,而不仅是稀松的颜色,因为我希望工具栏位于图片上方,但是它会出现在图片上方并覆盖其中的一部分以及所有内容倒在它后面的东西

Another issue I had is that I gave the toolbar initial colour and not just scrim colour because I wanted the Toolbar above the picture but instead it will go on top of the picture and will cover some of it as well as will cover anything that going to collapse behind it

在xml的工具栏中添加了颜色/样式:

added colour/style to the toolbar in the xml:

  1. 有没有办法从一开始就将工具栏放在图片上方,然后将图片折叠起来? (可以考虑保持工具栏处于固定状态,并在图像之前进行框架布局,但仍然会在状态栏区域折叠,这是主要问题.)


主要活动xml:


main activity xml:

<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="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim = "?attr/colorPrimary"
        app:statusBarScrim="?attr/colorAccent" --------> not changing
        android:id="@+id/my_ctl">


        <ImageView
            android:id="@+id/image"
            android:src="@drawable/flights"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            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"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_collapseMode="pin" />


    </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:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >

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

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

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


MainActivity.java:


MainActivity.java:

  CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.my_ctl);
    //ctl.setContentScrimColor(Color.RED);
    ctl.setStatusBarScrimColor(Color.BLUE);  --------> not working
    ctl.setTitle("blabla");

推荐答案

CollapsingToolbar app:statusBarScrim="?attr/colorAccent"更改为app:statusBarScrim="@android:color/transparent"

然后,您可以在代码中将 CollapsingToolbar 的颜色设置为ctl.setStatusBarScrimColor(Color.BLUE);

Then you can set the color of the CollapsingToolbar to ctl.setStatusBarScrimColor(Color.BLUE); in your code

还要确保将android:fitsSystemWindows="true"添加到 AppBarLayout

这篇关于CollapsingToolBarLayout-状态栏稀松布颜色不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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