美文网首页安卓Android开发Android技术知识
DrawerLayout中侧边栏NavigationView沉浸

DrawerLayout中侧边栏NavigationView沉浸

作者: T9的第三个三角 | 来源:发表于2017-08-04 09:57 被阅读659次

工作总结

  • 针对DrawerLayout中侧边栏NavigationView沉浸式状态栏无效问题,疏忽了一个问题,需要设置Activity的Style中
    <item="WindowTranslucentStatus">true</item> 属性,同时在设置NavigationView属性为 android:fitsSystemWindows="true",即可完成沉浸式状态栏效果
  • 设置下列效果
效果

设置Activity的布局中的父布局android:fitsSystemWindows="false",因为图片为AppBarLayout包裹,所以设置其android:fitsSystemWindows="true",同时设置包裹ImageView的父布局为android:fitsSystemWindows="true"
参照完整的Activity布局

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:fitsSystemWindows="true"
        android:theme="@style/MyTheme.AppBarOverlay">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="?attr/actionBarSize"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:statusBarScrim="@android:color/transparent">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7"
                app:layout_scrollFlags="scroll|snap|enterAlways|enterAlwaysCollapsed">

                <ImageView
                    android:id="@+id/newsImg"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:transitionName="@string/newsimg"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.4" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/transparent_black_10" />

                <com.ddz.lifestyle.customview.RobotoTextView
                    android:id="@+id/tv_news_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="35dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:maxLines="3"
                    android:textColor="@color/white"
                    android:textSize="22dp"
                    android:transitionName="@string/News"
                    app:typeface="roboto_medium"
                    tools:text="世界上但是对方发大水时多发发斯蒂芬撒地方少的地方撒地方撒地方" />

                <com.ddz.lifestyle.customview.RobotoTextView
                    android:id="@+id/tv_news_author"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="15dp"
                    android:gravity="right"
                    android:textColor="@color/white"
                    android:textSize="14sp"
                    tools:text="/@Jone" />
            </FrameLayout>


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="1"
                app:popupTheme="@style/MyTheme.PopupOverlay"
                app:theme="@style/MyTheme.AppBarOverlay" />
        </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:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <com.tencent.smtt.sdk.WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:isScrollContainer="false"
            android:overScrollMode="never"
            android:scrollIndicators="none" />

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

相关文章

网友评论

  • 爱吃板栗的小女孩:你好,我是用的drawlayout,我设置让drawerlayout实现沉浸式后,主布局部分颜色也没了,您知道怎么处理吗
    T9的第三个三角:主布局颜色消失?能上图看看吗

本文标题:DrawerLayout中侧边栏NavigationView沉浸

本文链接:https://www.haomeiwen.com/subject/tdstxxtx.html