laobie / StatusBarUtil

A util for setting status bar style on Android App.
http://t.cn/Rq746Kb
Apache License 2.0
8.82k stars 1.72k forks source link

跟布局是CoordinatorLayout toolbar会被通知栏遮盖 #56

Closed star-andy closed 7 years ago

star-andy commented 7 years ago

使用了你的方法也不行

laobie commented 7 years ago

@qinyang1018 说明下具体问题,你这样说的我不明白,有截图的话最好

star-andy commented 7 years ago

额 为什么我传上来的布局文件花图

laobie commented 7 years ago

你用的哪个方法呢?请具体说明问题,否则我不想浪费时间

laobie commented 7 years ago

@qinyang1018 重新截图发上来,不然没法看,具体说明你的问题,不行你先在我的 demo 上修改,看看效果

star-andy commented 7 years ago

布局的根视图是CoordinatorLayout ,用的 StatusBarUtil.setTranslucentForCoordinatorLayout(this, 50);这个方法

star-andy commented 7 years ago
   <?xml version="1.0" encoding="utf-8"?>
   <android.support.design.widget.CoordinatorLayout          xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:id="@+id/image_bg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/test_item"
                app:layout_collapseMode="parallax">

                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:alpha="0.5"
                    android:background="#cc000000" />

                <ImageView
                    android:id="@+id/team_icon"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="5dp"
                    android:src="@drawable/test_header" />

                <TextView
                    android:id="@+id/team_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/team_icon"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="2dp"
                    android:textColor="@color/white"
                    android:text="@string/test_name"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/team_leader"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/team_name"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="2dp"
                    android:text="@string/test_team_leader"
                    android:textColor="#dddddd"
                    android:textSize="12sp" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/team_leader"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="2dp"
                    android:orientation="horizontal">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:paddingBottom="2dp"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="2dp"
                        android:text="@string/test_team_type"
                        android:background="@drawable/team_detail_bg"
                        android:textColor="#dddddd"
                        android:textSize="12sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:gravity="center"
                        android:paddingBottom="2dp"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="2dp"
                        android:text="@string/test_team_age"
                        android:background="@drawable/team_detail_bg"
                        android:textColor="#dddddd"
                        android:textSize="12sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:paddingBottom="2dp"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="2dp"
                        android:text="@string/test_team_style"
                        android:background="@drawable/team_detail_bg"
                        android:textColor="#dddddd"
                        android:textSize="12sp" />

                </LinearLayout>
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleMarginTop="15dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/transparent"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:src="@drawable/nav_btn_back_white" />

                    <TextView
                        android:id="@+id/title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:text="@string/test_name" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="10dp"
                        android:text="@string/modify_info"
                        android:textColor="@color/white"
                        android:textSize="16sp" />

                </RelativeLayout>
            </android.support.v7.widget.Toolbar>

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

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            app:tabTextColor="@color/three"
            app:tabSelectedTextColor="@color/common_red"
            app:tabIndicatorColor="@color/common_red" />
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/common_line"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
star-andy commented 7 years ago

上面是布局文件

qq20161031-0 2x

这是效果图

qq20161031-1 2x

这是代码中使用的 还需要其他截图吗? 刚才实在不好意思

laobie commented 7 years ago

@qinyang1018 CollapsingToolbarLayout 有一个滑动变化状态栏的过程,本工具类无法处理 看这篇文章中后面提到的方法,处理这种布局 更简单更全的material design状态栏 - u013260551的专栏 - 博客频道 - CSDN.NET

star-andy commented 7 years ago

现在是不伸缩和折叠的状态都会被通知栏遮盖 我先看下您发的这个资料 thank you

laobie commented 7 years ago

@qinyang1018 你这个其实很简单,给 titleBar 设置一个 marginTop 就行了,状态栏的高度可以获取到,判断下版本就行

star-andy commented 7 years ago

恩 刚才去掉了theme里面的 true这个可以不被遮盖了 现在就剩全部伸展开时不是透明的 我看下你刚才发的那个资料 谢谢了

laobie commented 7 years ago

@qinyang1018 嗯 你这个需求看一下那篇文章,可以兼容到 4.4 的

star-andy commented 7 years ago

好的 谢谢了