Element at the bottom using AppBarLayout draws element behind Navigation bar












1















I am trying to have a navigation with fragments along different screens.
We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



So I use a NestedScrollView that will contain the fragments.
Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



The test is very easy to reproduce in the preview of the layout on AndroidStudio.



Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
Note that fitsSystemWindow does not make a difference for this.



This is just without using app:layout_scrollFlags="scroll"



enter image description here



This is using app:layout_scrollFlags="scroll"



enter image description here



This is the code for the simplified layout:



<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">

<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:layout_scrollFlags="scroll"
app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<android.support.v4.widget.NestedScrollView
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

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

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


also just in case this is the "content_main.xml"



    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity"
tools:showIn="@layout/activity_main">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:backgroundTint="@android:color/red"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>









share|improve this question





























    1















    I am trying to have a navigation with fragments along different screens.
    We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



    So I use a NestedScrollView that will contain the fragments.
    Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



    So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



    The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



    The test is very easy to reproduce in the preview of the layout on AndroidStudio.



    Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
    Note that fitsSystemWindow does not make a difference for this.



    This is just without using app:layout_scrollFlags="scroll"



    enter image description here



    This is using app:layout_scrollFlags="scroll"



    enter image description here



    This is the code for the simplified layout:



    <?xml version="1.0" encoding="utf-8"?>
    <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=".MainActivity">

    <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:layout_scrollFlags="scroll"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.v4.widget.NestedScrollView
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

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

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


    also just in case this is the "content_main.xml"



        <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 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=".MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:backgroundTint="@android:color/red"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
    </android.support.constraint.ConstraintLayout>









    share|improve this question



























      1












      1








      1








      I am trying to have a navigation with fragments along different screens.
      We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



      So I use a NestedScrollView that will contain the fragments.
      Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



      So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



      The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



      The test is very easy to reproduce in the preview of the layout on AndroidStudio.



      Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
      Note that fitsSystemWindow does not make a difference for this.



      This is just without using app:layout_scrollFlags="scroll"



      enter image description here



      This is using app:layout_scrollFlags="scroll"



      enter image description here



      This is the code for the simplified layout:



      <?xml version="1.0" encoding="utf-8"?>
      <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=".MainActivity">

      <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:layout_scrollFlags="scroll"
      app:popupTheme="@style/AppTheme.PopupOverlay" />

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

      <android.support.v4.widget.NestedScrollView
      android:fillViewport="true"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

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

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

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


      also just in case this is the "content_main.xml"



          <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout 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=".MainActivity"
      tools:showIn="@layout/activity_main">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World!"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      <Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="20dp"
      android:backgroundTint="@android:color/red"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent" />
      </android.support.constraint.ConstraintLayout>









      share|improve this question
















      I am trying to have a navigation with fragments along different screens.
      We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



      So I use a NestedScrollView that will contain the fragments.
      Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



      So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



      The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



      The test is very easy to reproduce in the preview of the layout on AndroidStudio.



      Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
      Note that fitsSystemWindow does not make a difference for this.



      This is just without using app:layout_scrollFlags="scroll"



      enter image description here



      This is using app:layout_scrollFlags="scroll"



      enter image description here



      This is the code for the simplified layout:



      <?xml version="1.0" encoding="utf-8"?>
      <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=".MainActivity">

      <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:layout_scrollFlags="scroll"
      app:popupTheme="@style/AppTheme.PopupOverlay" />

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

      <android.support.v4.widget.NestedScrollView
      android:fillViewport="true"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

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

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

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


      also just in case this is the "content_main.xml"



          <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout 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=".MainActivity"
      tools:showIn="@layout/activity_main">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World!"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      <Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="20dp"
      android:backgroundTint="@android:color/red"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent" />
      </android.support.constraint.ConstraintLayout>






      android android-layout android-fragments android-coordinatorlayout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 5:31









      Ümañg ßürmån

      3,27831130




      3,27831130










      asked Nov 22 '18 at 5:25









      egonzalegonzal

      946




      946
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <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=".MainActivity">

          <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:layout_scrollFlags="scroll"
          app:popupTheme="@style/AppTheme.PopupOverlay" />

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

          <android.support.v4.widget.NestedScrollView
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer
























          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

            – egonzal
            Nov 22 '18 at 17:13













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424381%2felement-at-the-bottom-using-appbarlayout-draws-element-behind-navigation-bar%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <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=".MainActivity">

          <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:layout_scrollFlags="scroll"
          app:popupTheme="@style/AppTheme.PopupOverlay" />

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

          <android.support.v4.widget.NestedScrollView
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer
























          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

            – egonzal
            Nov 22 '18 at 17:13


















          1














          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <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=".MainActivity">

          <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:layout_scrollFlags="scroll"
          app:popupTheme="@style/AppTheme.PopupOverlay" />

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

          <android.support.v4.widget.NestedScrollView
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer
























          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

            – egonzal
            Nov 22 '18 at 17:13
















          1












          1








          1







          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <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=".MainActivity">

          <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:layout_scrollFlags="scroll"
          app:popupTheme="@style/AppTheme.PopupOverlay" />

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

          <android.support.v4.widget.NestedScrollView
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer













          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <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=".MainActivity">

          <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:layout_scrollFlags="scroll"
          app:popupTheme="@style/AppTheme.PopupOverlay" />

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

          <android.support.v4.widget.NestedScrollView
          android:fillViewport="true"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 6:44









          Ümañg ßürmånÜmañg ßürmån

          3,27831130




          3,27831130













          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

            – egonzal
            Nov 22 '18 at 17:13





















          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

            – egonzal
            Nov 22 '18 at 17:13



















          Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

          – egonzal
          Nov 22 '18 at 17:13







          Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!

          – egonzal
          Nov 22 '18 at 17:13






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424381%2felement-at-the-bottom-using-appbarlayout-draws-element-behind-navigation-bar%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$