gpt4 book ai didi

android - 使用 DrawerLayout 和 Collapsing ToolbarLayout 不能有透明状态栏

转载 作者:行者123 更新时间:2023-11-29 19:30:12 29 4
gpt4 key购买 nike

首先,我对抽屉不在状态栏和此类问题没有任何问题。那工作正常。

其次,我们有一个很好的选择,可以使用 Collapsing Toolbar 显示透明的状态栏,并在其后面显示图像。例如 -

enter image description here

这里可以看到状态栏是透明的。

现在如果我使用 DrawerLayout 而不是 Cordinator 一个,(其中 Coordinator 是 DrawerLayout 的直接子级)我得到这个结果 -

enter image description here

这是我的代码 fragment -

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Dashboard">

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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


<ImageView
android:id="@+id/toolbarImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.7"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/morning_1"
app:layout_collapseMode="parallax" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/activity_dashboard_greeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Good Morning !!"
android:textColor="@color/white"
android:textSize="28dp" />

<com.meg7.widget.CircleImageView
android:id="@+id/activity_dashboard_image"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_below="@+id/activity_dashboard_greeting"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:src="@drawable/arrow_expense" />

</RelativeLayout>

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

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

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_margin="@dimen/activity_horizontal_margin"
android:src="@drawable/ic_add"
app:layout_anchor="@+id/appBar"
app:layout_anchorGravity="bottom|right" />

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

<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/menu_navigation">

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

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

请注意,尽管第一张图片的 Activity 不同,但第二张图片中的 Activity 完全相同。

感谢您的宝贵时间。提前致谢。

最佳答案

也将 android:fitsSystemWindows="true" 添加到 CoordinatorLayout。

关于android - 使用 DrawerLayout 和 Collapsing ToolbarLayout 不能有透明状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40179204/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com