Android Fragments 奇怪的白线顶部的行动栏

slhcrj9b  于 2023-04-21  发布在  Android
关注(0)|答案(3)|浏览(200)

我实现了一个DrawerNavigationView与一个BottomNavigationView在同一时间,但问题是**ActionBar**...默认片段是ok 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" />

</androidx.drawerlayout.widget.DrawerLayout>

问题片段的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">

</androidx.constraintlayout.widget.ConstraintLayout>

qkf9rpyu

qkf9rpyu1#

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

ubof19bj

ubof19bj2#

对于将来遇到同样问题的人,我发现解决方案是添加CoordinatorLayout作为根目录,将所有xml代码 Package 在主片段容器上,并使用android:fitsSystemWindows=“true”,现在一切正常!

kxeu7u2r

kxeu7u2r3#

对于使用CoordinatorLayoutAppBarLayout的普通活动中遇到它的任何人来说,在CoordinatorLayoutAppBarLayout中设置android:fitsSystemWindows="true"就可以了。

<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>

相关问题