简体   繁体   English

防止状态栏显示在具有 Notch 的设备中的 NavigationView 上

[英]Prevent statusbar to be shown over NavigationView in devices with Notch

I have an issue with my NavigationView , when it's expanded the statusBar is shown in semitransparent color over it and i would hide it completely by still keeping notch support.我的NavigationView有问题,当它展开时,状态栏以半透明颜色显示在它上面,我会通过仍然保持缺口支持来完全隐藏它。

It looks like this now:现在看起来像这样:

在此处输入图像描述

I've tried to add我试图添加

android:fitsSystemWindows="false" in my Activity but nothing chanded. android:fitsSystemWindows="false"在我的活动中,但没有任何变化。

My styles.xml looks like this:我的styles.xml 看起来像这样:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorAccent</item>
        <item name="primaryTextColor">#F4F4F6</item>
        <item name="colorControlNormal">@color/colorAccent</item>
        <item name="secondaryTextColor">#96000000</item>
        <item name="recyclerViewTitleColor">#96000000</item>
        <item name="navColor">#2948ff</item>
        <item name="colorTurni">@color/blueLight</item>
        <item name="varianti">@color/green</item>
        <item name="blueDark">@color/blueDark</item>
        <item name="backgroundCardColor">#FFFF</item>
        <item name="bottomSheetDialogTheme">@style/ThemeOverlay.App.BottomSheetDialog</item>
        <item name="android:windowLayoutInDisplayCutoutMode">
            shortEdges
        </item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>

What i would reach is this:我要达到的是:

在此处输入图像描述

Activity.xml活动.xml

<androidx.drawerlayout.widget.DrawerLayout android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FAFAFA"
    android:orientation="vertical"
    tools:context="it.gabtamagnini.visualposmobile.PtermActivity">


    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    ...

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_menu"
        android:layout_width="185dp"
        android:layout_height="match_parent"
        android:fitsSystemWindows="false"
        android:background="@color/white"
        android:layout_gravity="start"
        app:headerLayout="@layout/layout_header">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewMenu"
            android:layout_width="match_parent"
            android:layout_marginTop="120dp"
            android:layout_height="match_parent"
            tools:listitem="@layout/layout_menu"
            android:clipToPadding="false"
            android:paddingBottom="15dp"
            android:paddingEnd="5dp"
            android:paddingStart="5dp" />

    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

Cause:原因:

This shadow is related to the drawable used for the inset foreground which is customized to R.styleable.ScrimInsetsFrameLayout_insetForeground style by default on the NavigationView ;此阴影与用于嵌入前景的可绘制对象有关,默认情况下在NavigationView上自定义为R.styleable.ScrimInsetsFrameLayout_insetForeground样式; this answer explains more about the ScrimInsetsFrameLayout class.这个答案解释了有关ScrimInsetsFrameLayout类的更多信息。

Solution:解决方案:

Getting rid of this drawable from the NavigationView either programmatically or in layout:以编程方式或布局从NavigationView中删除此可绘制对象:

Programmatically: setting setScrimInsetForeground to null.编程方式:setScrimInsetForeground设置为 null。

navView.setScrimInsetForeground(null)

In layout: using app:insetForeground="@null" :在布局中:使用app:insetForeground="@null"

<com.google.android.material.navigation.NavigationView
    android:id="@+id/nav_menu"
    ....
    app:insetForeground="@null"/>

Use this in your NavigationView not in activity在您的NavigationView中使用它而不是在activity

android:fitsSystemWindows="false"

it will solve your issue它会解决你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android中将状态栏填充设置为NavigationView - Setting Statusbar padding to NavigationView in Android 棒棒糖设备中的我的材料设计ActionBar或StatusBar上没有显示颜色,但Pre-Lollipop设备中的ActionBar中没有显示颜色。 为什么? - No color is shown on my Material Design ActionBar or StatusBar in Lollipop devices, but is shown in ActionBar of Pre-Lollipop devices. Why? 在缺口设备模拟器上测试应用程序 - Testing an app on notch devices emulators 如何将 SafeAreaView 用于 Android 缺口设备? - How to use SafeAreaView for Android notch devices? 如何在android中为缺口设备获得安全区域 - How to get safe area in android for notch devices 工具栏内容在状态栏上可见 - Toolbar content visible over statusbar NavigationView 中的分隔线(在 BottomSheetDialogFragment 中)未显示? - Divider in a NavigationView (in BottomSheetDialogFragment) doesn't shown? 在运行时从片段启用全屏不适用于具有缺口的设备 - Enabling full screen at runtime from fragment not working with devices having notch NavigationBar 和 StatusBar 在某些设备上不完全透明 - NavigationBar and StatusBar not fully transparent on some devices 某些设备未显示通知 - Notifications is not shown in some devices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM