Search code examples
android-studioandroid-fragmentsandroid-actionbarnavigation-drawer

Weird white line on top of Action Bar


I implemented a DrawerNavigationView with a BottomNavigationView at the same time, but the problem is the ActionBar... The default fragment is ok enter image description here But changing fragment it creates a weird white line on the top of the ActionBar, which is not anymore in the right position... Do u maybe know why?enter image description here Thank u for help D:

XML Code for main activity container for fragments

<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 code for fragment with the problem (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>


Solution

  • For who has the same problem in future I found the solution adding as a root a CoordinatorLayout wrapping all the xml code on the main fragment container and using android:fitsSystemWindows="true" on it, everything working fine now!