半透明状态栏不半透明

时间:2021-04-22 15:18:28

标签: android material-design

我尝试实现半透明的操作栏,如here所述:

效果应该是这样的:

enter image description here

我对布局进行了以下更改:

> <androidx.coordinatorlayout.widget.CoordinatorLayout  
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".fragments.HotelFragment">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            .....
            android:fitsSystemWindows="true">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/d" />

            <androidx.appcompat.widget.Toolbar
                     ....
                android:background="@android:color/transparent"
               />

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

在主题中:

    <item name="android:windowTranslucentStatus">true</item>>

效果就像:

enter image description here

我的最低 API 是 21。

1 个答案:

答案 0 :(得分:1)

在活动中添加这个。 window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)