1

I have a fragment in my app that has a scroll view for the signup and login pages. Right now there isn't enough content in the scroll view to actually make it scroll, however when the keyboard appears, it does cover up most of the content in the view. This causes a lot of issues especially on devices with smaller screens, it blocks a lot, and the view is NOT scrollable, so I have to close the keyboard to get to the rest of the inputs.

I need the bottom of the fragments frame layout to be pushed up to JUST above the top of the keyboard, so the keyboard won't actually hide any content, and still allow the scroll view to actually scroll to the rest of the content.

I have seen the usual fix to an issue similar to this, which would to change the AndroidManifest.xml to the following:

android:windowSoftInputMode="adjustResize"

but this will push up the entire page, which includes the footer view I have under and outside of the login and signup fragment layouts. It makes my scrollview smaller and allows for it to scroll, but I need the footer to stay hidden under the keyboard still.

I think a work around to this would be to have override onConfigurationChanged(); in MyActivity that will detect if the keyboard has appeared, and if it has, push the bottom of the framelayout to be JUST above the keyboard, thus making the scroll view smaller, and allowing us to actually scroll. I am not quite sure HOW to do this though.

Here is what it looks like with the keyboard up, blocking the content. This would be okay IF the scroll view was scrollable, allowing me to see the rest of the content, however it will not scroll and the only way to access the content under it is to close the keyboard first.

EDIT I was able to use the answer below, editing the Android manifest for

android:windowSoftInputMode="adjustResize"

and the first method using the code below

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
            ... do something here
        }
     }
});

I had it adjust my views so the footer would be pushed way down below, then resize the layout holding the fragment to extend down allowing it to be scrollable still.

Jake Weso
  • 555
  • 1
  • 6
  • 14
  • you mean push only part of screen up? – KOTIOS Jul 17 '14 at 03:31
  • @adcom I need the bottom of the frame layout containing the fragment to be pushed up RIGHT after the top of the keyboard. Resizing the scrollview so the keyboard doesn't cover any of it, and the scrollview will be scrollable again – Jake Weso Jul 17 '14 at 03:34
  • I think [this answer](http://stackoverflow.com/a/21202586/669647) will give you some idea. – penkzhou Jul 17 '14 at 03:34
  • @penkzhou Sorry, that doesn't help, I need the footer to stay under the keyboard while resizing the view the fragment is in to keep the bottom of the view just above the keyboard, and allowing me to scroll through the content in it – Jake Weso Jul 17 '14 at 03:49
  • @JakeWeso I received your email, give me sometime to dig back what I did to solve this :) – Roy Lee Jul 17 '14 at 04:45
  • @Roylee I appreciate it! Seems to be just what I am looking for myself! :) – Jake Weso Jul 17 '14 at 04:46
  • @JakeWeso Let me know if you need more information, fyi I'm using the second approach, if you are stuck, I will post the code snippets here :) – Roy Lee Jul 17 '14 at 05:45

1 Answers1

0

Okay, here's how I solved it.


The basic idea is that you have to:

  1. Detect whether or not a soft-keyboard is showing,
  2. React. Based on the detected information (is-soft-keyboard-showing), resize your layout accordingly.

There are two ways of achieving this:

  1. to give your activity's root view a known ID, say '@+id/activityRoot', hook a GlobalLayoutListener into the ViewTreeObserver, and from there calculate the size diff between your activity's view root and the window size:

  2. Customize your top-level layout class into one which overrides onMeasure()

And I would like to credit the above answer to this SO Post: how-to-check-visibility-of-software-keyboard-in-android, which I have found earlier on this particular problem.

Community
  • 1
  • 1
Roy Lee
  • 10,572
  • 13
  • 60
  • 84
  • 1
    Thanks so much Roylee! I used the first way and it works fantastically, I have it changing the margins of my views to hide the footer, and resize the fragment holder so it becomes scrollable again! – Jake Weso Jul 18 '14 at 00:30