title: elements going behind status bar and bottom navigation bar
body: <p><a href="https://i.stack.imgur.com/gnneD.jpg" rel="nofollow noreferrer">bottom navigation view is going behind bottom nav bar and the toolbar is going behind the status bar</a></p>
  <p>I am new to android and I have been stuck with this issue from day one. I have tried to set specific margins for the toolbar and bottomnavigationview but I don't think it's a good solution. Can someone please help me with this. I have also tried
  android:fitsystemwindows = &quot;true&quot;
  but it did not work. below is the fragment's xml code</p>
  <pre><code>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com  /apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot;
      tools:context=&quot;fragments.homeUi&quot;&gt;
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
          &lt;androidx.appcompat.widget.Toolbar
              android:id=&quot;@+id/toolbar&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;65dp&quot;
              android:background=&quot;?attr/colorPrimary&quot;
              android:minHeight=&quot;?attr/actionBarSize&quot;
              android:theme=&quot;?attr/actionBarTheme&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
      &lt;TextView
          android:id=&quot;@+id/textView4&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;167dp&quot;
          android:layout_marginBottom=&quot;78dp&quot;
          android:text=&quot;@string/home&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/signOutButton&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.029&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot; /&gt;
  
      &lt;Button
          android:id=&quot;@+id/signOutButton&quot;
          android:layout_width=&quot;100dp&quot;
          android:layout_height=&quot;50dp&quot;
          android:layout_marginStart=&quot;143dp&quot;
          android:layout_marginTop=&quot;44dp&quot;
          android:layout_marginEnd=&quot;168dp&quot;
          android:text=&quot;@string/signout&quot;
          android:textAllCaps=&quot;false&quot;
          android:textColor=&quot;#736B3B&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.0&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/textView4&quot; /&gt;
  
      &lt;androidx.cardview.widget.CardView
          android:id=&quot;@+id/cardView&quot;
          android:layout_width=&quot;409dp&quot;
          android:layout_height=&quot;230dp&quot;
          android:layout_marginStart=&quot;1dp&quot;
          android:layout_marginTop=&quot;140dp&quot;
          android:layout_marginEnd=&quot;1dp&quot;
          android:layout_marginBottom=&quot;116dp&quot;
          app:cardCornerRadius=&quot;10dp&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/textView4&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
          &lt;androidx.viewpager2.widget.ViewPager2
              android:id=&quot;@+id/viewPagerHome&quot;
              android:layout_width=&quot;409dp&quot;
              android:layout_height=&quot;230dp&quot;
              app:layout_constraintCircleRadius=&quot;100dp&quot;&gt;
  
          &lt;/androidx.viewpager2.widget.ViewPager2&gt;
      &lt;/androidx.cardview.widget.CardView&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id=&quot;@+id/bottomNavbar&quot;
          android:layout_width=&quot;409dp&quot;
          android:layout_height=&quot;73dp&quot;
          android:layout_marginStart=&quot;1dp&quot;
          android:layout_marginEnd=&quot;1dp&quot;
          android:background=&quot;#fff&quot;
          app:itemIconTint=&quot;@drawable/bottom_nav_icon_color&quot;
          app:itemTextColor=&quot;#00B8B4&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:menu=&quot;@menu/bottom_nav&quot; /&gt;
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>here is the activity's xml file</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.HomeActivity&quot;&gt;
  
      &lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/fragmentContainerView&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;409dp&quot;
          android:layout_height=&quot;867dp&quot;
          android:layout_marginStart=&quot;1dp&quot;
          android:layout_marginTop=&quot;1dp&quot;
          android:layout_marginEnd=&quot;1dp&quot;
          android:layout_marginBottom=&quot;1dp&quot;
          app:defaultNavHost=&quot;true&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:navGraph=&quot;@navigation/nav_home_acitvity&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>