Search code examples
androidkotlinandroid-actionbar

Notification bar cause problem with DrawerLayout and Activity


I would like to add a custom actionbar in my app because I am using a DrawerLayout, here is the problem:

enter image description here

Here is my theme:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

In the onCreate() of my activity I added:

   setContentView(R.layout.activity_talk)
   setSupportActionBar(toolbar)

activity_talk.xml

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    />

<include
    layout="@layout/activity_talks_child"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"/>

</android.support.v4.widget.DrawerLayout>

app_bar_main.xml:

<android.support.design.widget.CoordinatorLayout 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"
tools:context=".TalksActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_red_dark"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/holo_red_dark"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/activity_talks_child" />

</android.support.design.widget.CoordinatorLayout>

I do not know how to align the actionbars...

Thank you


Solution

  • I finally found the solution.

    A added android:fitsSystemWindows="true" on the ConstraintLayout in app_bar_main.xml

    I also added this line (android:fitsSystemWindows="true") in the first element of the nav_header_main.xml file (this is the headerLayout included in activity_talk.xml.