当前位置:网站首页>Solve the problem that the input box is blocked by the pop-up keyboard under the WebView transparent status bar

Solve the problem that the input box is blocked by the pop-up keyboard under the WebView transparent status bar

2022-06-26 03:36:00 kingsley1212

Create a new class

public class WindowSoftModeAdjustResizeExecutor {

public static void assistActivity(Activity activity) {
    new WindowSoftModeAdjustResizeExecutor(activity);
}

private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;

private WindowSoftModeAdjustResizeExecutor(Activity activity) {
    FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
    mChildOfContent = content.getChildAt(0);
    mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            possiblyResizeChildOfContent();
        }
    });
    frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}

private void possiblyResizeChildOfContent() {
    int usableHeightNow = computeUsableHeight();
    if (usableHeightNow != usableHeightPrevious) {
        int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
        int heightDifference = usableHeightSansKeyboard - usableHeightNow;

        frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;

        mChildOfContent.requestLayout();
        usableHeightPrevious = usableHeightNow;
    }
}

private int computeUsableHeight() {
    Rect r = new Rect();
    mChildOfContent.getWindowVisibleDisplayFrame(r);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return (r.bottom - r.top);
    }
    return r.bottom;
}
}

In use . Which one? Activity It's covered , Just call this code

  /**
     *  Solve the problem under the transparent status bar , Pop up the problem that the keyboard blocks the input box 
     */
    WindowSoftModeAdjustResizeExecutor.assistActivity(this);

And it should be in the corresponding... Of the manifest file activity It says in it

android:windowSoftInputMode="adjustResize|stateHidden"
原网站

版权声明
本文为[kingsley1212]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180547453055.html