操作栏顶部奇怪的白线

问题描述 投票:0回答:3

我同时实现了一个带有

DrawerNavigationView
BottomNavigationView
,但问题是
ActionBar
...默认片段是好的enter image description here但是改变
fragment
它创建了一个奇怪的白线
ActionBar
的顶部,它不再位于正确的位置......你知道为什么吗?enter image description here谢谢你的帮助D:

片段的主要活动容器的 XML 代码

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        android:theme="@style/Theme2"
        app:itemIconTint="@color/white_darker"
        app:itemRippleColor="@color/white_darker"
        app:itemTextColor="@color/white_darker"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/drawer_header"
    app:itemTextAppearance="?textAppearanceListItem"
    app:menu="@menu/navigation_drawer" />

问题片段的 XML 代码(Empty ConstraintLayout)

<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/dark"
tools:context=".HomeUi.Notifications.NotificationsFragment">

android-studio android-fragments android-actionbar navigation-drawer
3个回答
0
投票

在您的

styles.xml
文件中,在
NoActionBar
之后尝试
parent
。其他问题可能是您的
linearlayout
中有一个
fragment
的其余部分。


0
投票

对于将来遇到同样问题的人,我找到了解决方案,将 CoordinatorLayout 作为根添加,将所有 xml 代码包装在主片段容器上,并在其上使用 android:fitsSystemWindows="true",现在一切正常!


0
投票

对于使用

CoordinatorLayout
AppBarLayout
在普通活动中体验它的任何人。在
android:fitsSystemWindows="true"
CoordinatorLayout
中设置
AppBarLayout
就可以了。

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:fitsSystemWindows="true"
    >
    <com.google.android.material.appbar.AppBarLayout
       android:fitsSystemWindows="true"
       >
    </com.google.android.material.appbar.AppBarLayout>
    
    ...

</androidx.coordinatorlayout.widget.CoordinatorLayout>
© www.soinside.com 2019 - 2024. All rights reserved.