7

Got a weird problem. Contents of the fragment getting hidden under the action bar. Its a pretty basic drawer layout and a fragment.

enter image description here

New to android and don't know if this is how it is. I used margin just to pull this down, as you can see below. But this doesn't sound correct to me... please throw some light where am I going wrong. Thanks in Advance.

enter image description here

Mouli
  • 165
  • 2
  • 12
  • 2
    are you using the ACTION_BAR_OVERLAY flag? – Blackbelt Jul 21 '14 at 09:55
  • oh my goodness... yes! android:windowActionBarOverlay set to true... Thank you very much. Please add this as answer I will accept. @blackbelt – Mouli Jul 21 '14 at 10:01
  • @Mouli : I know its a long time since this post was updated. But i am having the same issue now. I have added android:windowActionBarOverlay to false in my styles.xml but still part of textview is hidden behind my action bar. Am i adding it in the right place or should i add this somewhere else. Please help – Sriram Apr 16 '16 at 08:03
  • Is your content wrapped probably in scroll view that on start "scroll" down the content? – murt Jul 18 '16 at 15:51

4 Answers4

3

It is the normal and expected behaviour if you set FEATURE_ACTION_BAR_OVERLAY (android:windowActionBarOverlay) . Here the documentation

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I know its a long time since this post was updated. But i am having the same issue now. I have added android:windowActionBarOverlay to false in my styles.xml but still part of textview is hidden behind my action bar. Am i adding it in the right place or should i add this somewhere else. Please help – Sriram Apr 16 '16 at 08:05
  • Are you using the CoordinatorLayout? – Blackbelt Apr 16 '16 at 08:12
  • 1
    Yes . CoordinatorLayout for the app bar. I am using the default "Navigation Drawer" activity by android for my project. When i add a fragment, part of the textview hides behind the action bar – Sriram Apr 16 '16 at 08:19
  • You need a special attribute in your XML in this case. Look for it – Blackbelt Apr 16 '16 at 08:56
  • Sorry for the trouble. but special attribute?? – Sriram Apr 16 '16 at 10:00
  • 3
    Have a look here: http://stackoverflow.com/questions/35162465/framelayout-shown-above-appbarlayout – Blackbelt Apr 16 '16 at 13:17
  • 3
    Thanks much. I was able to fix it by adding "@string/appbar_scrolling_view_behavior" . Thanks again – Sriram Apr 18 '16 at 05:42
1

Add an attribute app:layout_behavior="@string/appbar_scrolling_view_behavior" to your parent view of your fragment.

0

Another possible solution for many who see this question is to change the parent layout of the toolbar to LinearLayout (likely with a vertical orientation), as this type of layout does not allow its children to overlap.

For example, this layout in activity_main.xml will result in the fragment being below the toolbar, rather than behind it:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>
    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <androidx.fragment.app.FragmentContainerView
            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:navGraph="@navigation/nav_graph"/>
    </FrameLayout>
</LinearLayout>
Daniel C Jacobs
  • 691
  • 8
  • 18
0

Setting top margin of the fragment's layout to height of AcionBar worked, at last!!

android:layout_marginTop="?attr/actionBarSize" 

Don't know if this is a better solution but for me this is the only working solution.

cigien
  • 57,834
  • 11
  • 73
  • 112
Biju
  • 11
  • 2