adjustResize: trying to not display bottom bar of Split Action Bar when keyboard is visible

885 Views Asked by At

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.

1

There are 1 best solutions below

1
On

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);
        }
     }
});