2

I have a BaseActivity which contains the navigation drawer. So , now my other activities will extends from the baseActivity to get the navigation drawer as well.

This is my app_bar layout

<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"
    android:fitsSystemWindows="true"
    tools:context="com.example.matt_pc.dissertationv2.HomeActivity">


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

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

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


        <include
            layout="@layout/content_home"
            android:layout_marginTop="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    <com.andremion.counterfab.CounterFab
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@android:color/white"
        app:srcCompat="@drawable/ic_shopping_cart_black_24dp" />

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

This is my content_main

<FrameLayout 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/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".HomeActivity"
    tools:showIn="@layout/app_bar_home"
    />

My navigation drawer.

<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"
    android:background="@mipmap/background"

    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_home"
        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_home"

        android:background="@color/overlayBackground"
        app:itemTextColor="@color/white"
        app:itemIconTint="@android:color/white"
        app:menu="@menu/activity_home_drawer" />

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

The problem is my toolbar is overlapping my contents.See below. enter image description here

Any help on this?

Stefano Tokyo
  • 85
  • 1
  • 10
  • you are using `AppBarLayout` incorrectly see this: https://developer.android.com/reference/android/support/design/widget/AppBarLayout and also this may help you: https://stackoverflow.com/questions/35181299/where-should-applayout-behavior-be-set – ygngy Sep 29 '18 at 21:48

2 Answers2

0

Try delete your AppBar theme and toolbar popupTheme:

  • android:theme="@style/AppTheme.AppBarOverlay"
  • app:popupTheme="@style/AppTheme.PopupOverlay"
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
Aleksandr Melnikov
  • 310
  • 1
  • 3
  • 10
0

I'm guessing that either using two appbar_scrolling_view_behavior or, when replacing the Fragment would cause the issue.

So, if you have something like this in your app (when trying to show Fragment):

..replace(android:R.id.content, yourfragment())

Change the view to your FrameLayout id content_frame:

..replace(R.id.content_frame, yourfragment())

And use the layout it as follows:

<android.support.design.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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

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

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <com.andremion.counterfab.CounterFab
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@android:color/white"
        app:srcCompat="@drawable/ic_shopping_cart_black_24dp" />

</android.support.design.widget.CoordinatorLayout>
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • I am not using any fragment :( – Stefano Tokyo Sep 29 '18 at 20:52
  • FrameLayout in there is used to show Fragments inside CoordinatorLayout. Perhaps making it a bit clear of why you’re using FrameLayout in there might help to give you the right solution. Anyways, did you try my pasted layout? – ʍѳђઽ૯ท Sep 30 '18 at 06:58