2

I have received an android project code and I need to add material toolbar in a fragment. Everything went well but I noticed the toolbar always goes under OS status bar in the top of the screen as shown in the following screenshot:

Toolbar goes under OS status bar

So why toolbar header goes under the OS status bar here? and how to make status bar pushed to start where the OS status bar ends?

here is the fragment xml code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/wifi_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/orange_500" />

    <com.google.android.material.tabs.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/watch" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/downloads_item" />

    </com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager.widget.ViewPager
    android:id="@+id/wifi_view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Khaled
  • 345
  • 5
  • 14

2 Answers2

1

Add below link into your parent xml tag which is CoordinatorLayout in your case. Toolbar will appear below the status bar.

android:fitsSystemWindows="true"
rasfarrf5
  • 219
  • 1
  • 5
0

Are you using getWindow() in your activity ? Please remove it and test again .

B001ᛦ
  • 2,036
  • 6
  • 23
  • 31