2

I have an app that has 4 Fragments (displayed as tabs), and all of them share the same split Action Bar. The top bar has the tabs' buttons and the bottom bar has the actions' buttons. There's one Fragment that has an EditText at the top and a ListView under it.
Now, the problem with the keyboard in this Fragment is:

if I use adjustPan to make the keyboard cover the bottom bar, the ListView doesn't get resized, so some of its elements get covered by the keyboard and I can't scroll to see them;

if I use adjustResize, the ListView does get resized, but the bottom bar gets pushed up, of course. I don't want that.

What I'd like is that the bottom bar gets covered by the keyboard AND the ListView gets resized so that I can see all of its elements by scrolling.
In the meantime, I'm going to use adjustPan and make the keyboard disappear when the user touches the ListView, but I'd like to find a way to make what I explained above.

Is it a bad idea to try to resize the ListView programmatically when the keyboard appears (while using adjustPan)? Or is there a way to hide (with setVisibility(View.GONE) or something) the bottom bar while using adjustResize? And lastly, is there an easy way to understand when the keyboard appears and to get its height?

Thanks for the help.

P.S. I've already found all the few similar questions, and none of them have a solution.

nonzaprej
  • 1,322
  • 2
  • 21
  • 30

1 Answers1

0

The one thing I could think of is setting the softInputMethodMode to adjustResize then showing or hiding the bottom bar when the keyboard closes and opens. Although there aren't any keyboard open/close events to listen to, you can detect it by observing changes in the window height. You can achieve this by adding a global layout listener to your main content view's view tree observer. Check out this post for an explanation and code of using a view tree observer.

Edit

Here's a snippet that I copied from the link above with relevant changes (I haven't tried this out, but it highlights the idea) :

View bottomBar = findViewById(R.id.your_bottom_bar);
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...
            bottomBar.setVisibility(View.GONE);
        }else{
            bottomBar.setVisibility(View.VISIBLE);
        }
     }
});
Community
  • 1
  • 1
WindsurferOak
  • 4,861
  • 1
  • 31
  • 36
  • thanks, I'll look into it tomorrow. by the way, my bottom bar is not a view that I defined in an xml file, but it's created because I use an ActionBar and I have set `android:uiOptions="splitActionBarWhenNarrow"` in the main activity's element in the app's manifest. I don't know how to get a reference to only the bottom part, but I'll look into it. – nonzaprej May 01 '15 at 20:24