Asked  7 Months ago    Answers:  5   Viewed   186 times

I have a vertical sliding drawer at the bottom of my app. When the soft keyboard opens, it pushes the tab for the drawer up, so it sits atop the keyboard. I actually want it to remain at the bottom of the screen, becoming hidden when the keyboard is shown.

Anyone else run into this issue? Know how to fix it?

 Answers

77

You can simply switch your Activity's windowSoftInputModeflag to adjustPan in your AndroidMainfest.xml file inside your activity tag.

Check the official documentation for more info.

<activity
   ...
   android:windowSoftInputMode="adjustPan"> 
</activity>

If your container is not changing size, then you likely have the height set to "match parent". If possible, set the parent to "Wrap Content", or a constraint layout with constraingts to top and bottom of parent.

The parent container will shrink to fit the available space, so it is likely that your content should be inside of a scolling view to prevent (depending on the phone manufacturer and the layout choosen...)

  1. Content being smashed together
  2. Content hanging off the screen
  3. Content being inacccessable due to it being underneath the keyboard

even if the layout it is in is a relative or constraint layout, the content could exhibit problems 1-3.

Tuesday, June 1, 2021
 
hjalpmig
answered 7 Months ago
95

Finally figured out!

I used

public void supressKeyboard() {
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
}

for the activities where I want to suppress the keyboard(you can put it in a general activity where all other activities inherit from)

But this won't prevent the keyboard from popping up when you click on the EditText textbox. What I did is I consumed the onTouch event for the text box:

@Override
public boolean onTouchEvent(MotionEvent event) {
    return true;
}
Wednesday, August 4, 2021
 
mgierw
answered 4 Months ago
42

programmatically you could use, capturing the view of the active activity on the screen of the device.

public final void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
        View focus = getCurrentFocus();
        if (focus != null) {
            hiddenKeyboard(focus);
        }
    }
public final void onTabselected(Tab tab, FragmentTransaction fragmentTransaction) {
        View focus = getCurrentFocus();
        if (focus != null) {
            hiddenKeyboard(focus);
        }
    }
public final void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
        View focus = getCurrentFocus();
        if (focus != null) {
            hiddenKeyboard(focus);
        }
    }

private void hiddenKeyboard(View v) {
        InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        keyboard.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
Saturday, August 14, 2021
 
SJain
answered 4 Months ago
11

The default IME mode set on the activity in the manifest (android:windowSoftInputMode="adjustPan") will pan the main layout so the text field is in the middle of the viewable area. While the majority of your content is in a scrollable region, it is simply moving the whole region and not scrolling the contents into view. If you use android:windowSoftInputMode="adjustNothing" it will prevent the layout panning, but will also effectively do nothing and just cover your original input.

MY recommendation would be to use adjustResize, this might fix it for you. If not, you have to look into doing some custom scroll-region focusing.

Saturday, October 30, 2021
 
Lak
answered 1 Month ago
Lak
67

Did you overwrite onLayout? When Android lays out your ViewGroup, your ViewGroup is responsible for laying out the children.

This code is from a custom ViewGroup that lays out all children on top of each other:

@Override
protected void onLayout(final boolean changed, final int l, final int t, final int r, final int b) {

    int count = this.getChildCount();
    for (int i = 0; i < count; i++) {

        View child = this.getChildAt(i);
        child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
    }
}

For completeness, the onMeasure override:

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {

    int parentWidth  = MeasureSpec.getSize(widthMeasureSpec);
    int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
    this.setMeasuredDimension(parentWidth, parentHeight);

    int count = this.getChildCount();
    for (int i = 0; i < count; i++) {

        View child = this.getChildAt(i);
        this.measureChild(
            child,
            MeasureSpec.makeMeasureSpec(parentWidth, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(parentHeight, MeasureSpec.EXACTLY));
    }
}
Monday, November 29, 2021
 
Ben Rowe
answered 5 Days ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share