39

How can i create a sticky footer that wont be moved up with the view when the softkey keyboard popups up?

Below is an image example of my current setup and what i want to achieve. I have a scrollview that contains my page content and a linearlayout that is aligned to the parent bottom that acts as a nav bar.

Example of what i want it to do

Problem is that when the keyboard popups, it pushes my entire view up, including the bottom nav section. I do not want to disable the automatic pushing up of the view (by setting android:windowSoftInputMode="adjustPan") but rather exclude a single element from being pushed up, my bottom nav bar.

I have tested the windowSoftInputMode fix but it hides my page content behind the keyboard. Is there a way to have it continue pushing up the scrollview but not the bottom nav? My other option was to set visibility:gone on keyboard up and then reshow it on keyboard down, but that seems overly complicated and not always reliable from what i read.

If anyone has any examples or suggestions, i'm all ears. Thanks.

Thomas Stein
  • 671
  • 1
  • 7
  • 11
  • I am very late but I have posted an answer, so anyone facing this problem, please go through my answer once, it might save your time and energy. – gprathour Mar 23 '19 at 14:53

5 Answers5

22

Either add this as scrollbar's XML attribute

android:isScrollContainer="false"

or add this in Activity's tag in Manifest

android:windowSoftInputMode="adjustPan"

JiratPasuksmit
  • 672
  • 7
  • 18
10

I tried a lot of solutions found on SO and only adding android:windowSoftInputMode="adjustNothing" into the manifest for the activity worked for me:

<activity
    android:name=".MainActivity"
    android:windowSoftInputMode="adjustNothing">

I include the associated layout because your solution is highly dependent on your layout, so this solution worked for me in this case:

  <RelativeLayout
     ...
        <android.support.v4.widget.NestedScrollView
           ...
        </android.support.v4.widget.NestedScrollView>
        <android.support.design.widget.BottomNavigationView
             ...
            design:menu="@menu/navigation"/>
    </RelativeLayout>
saswanb
  • 1,975
  • 1
  • 17
  • 25
  • 3
    I've run into the same problem as OP and while `android:windowSoftInputMode="adjustNothing"` makes the keyboard cover the footer (which stays at the bottom of the screen), the ScrollView doesn't get pushed up and loses its scrolling ability, which means that in the end part of it are behind the keyboard and inaccessible. – Neph Jun 21 '18 at 13:05
  • Good point @Neph - I've also found that the solution is highly dependent on your entire view hierarchy and what works in one instance has undesirable consequences in another. – saswanb Jun 21 '18 at 16:55
  • you r great! helped this – Mayura Devani Apr 30 '21 at 10:57
5

Just add this line in your onCreate, When this option set the window not adjust for a shown input method. :

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
ucMedia
  • 4,105
  • 4
  • 38
  • 46
  • 1
    Do this in the on the onCreate method of your activity. It will then apply to all fragments within that activity. – timeSmith Sep 05 '19 at 06:57
3

I am very late to answer but I ran into same situation lately. I followed another approach to solve this issue and that was rather than using RelativeLayout or LinearLayout, using CoordinatorLayout and having behavior applied to BottomNavigtaionView to show/hide it with scrolling to top or bottom (the same way we see CollapsingToolBar or AppBarLayout).

The built in behavior used for BottomNavigationView is app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"

You can read all steps in detail from my another answer here.

P.S. I posted it as an answer rather than a comment because sometimes we just look for answers and ignore the comments and I believe it could be a good approach to solve this issue, so you should not ignore it and give it a read once. Thanks.

gprathour
  • 14,813
  • 5
  • 66
  • 90
1

I've come across a pretty similar problem with the differences that a) I wasn't using a ScrollView at first and b) the item I didn't want to move was a simple TextView.

Here's the answer I found: click

What I did to fix it:

  • Use adjustResize
  • Use 4 Layouts: A surrounding one, 1 for the header, the ScrollView and 1 for your "bottom nav"
  • Don't just rely on android:layout_alignParentBottom="true", while this will move your navigation bar to the bottom of the screen, it also means that the keyboard can move it up because of "adjustResize"
  • Additionally use android:layout_height="wrap_content" in combination with android:layout_below="@id/MyScrollView" (so the layout will use up all the space it can get between the ScrollView and the bottom of the screen) and android:gravity="bottom" to simply have everything at the bottom of the layout.
  • You might also be able to use android:layout_height="match_parent" instead of android:layout_alignParentBottom="true" and android:layout_height="wrap_content" but I didn't fully test it like that.
  • Like I said, this will make the "bottom nav" layout use up all the space it can get below the ScrollView. If you don't want that, e.g. because your "bottom nav" has a different color you don't want to be shown too much, try creating a surrounding RelativeLayout for "bottom nav" and another empty layout inside that can push "bottom nav" downwards. ;)
Neph
  • 1,823
  • 2
  • 31
  • 69