Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

Android在全屏下ScrollView包裹EditText软键盘弹出后,ScrollView无法滚动

问题描述

在全屏下ScrollView包裹EditText软键盘弹出后,ScrollView无法滚动,设置adjustResize无效

解决方法

参考:https://stackoverflow.com/questions/21092888/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar

在Activity的根布局上设置属性:

android:windowSoftInputMode="stateVisible|adjustResize"
android:fitsSystemWindows="true"

adjustResize就可以成功的起作用,但以上做法会导致Toolbar向下平移了statusBar的高度,所以必须重写根布局Layout

解决办法:

(1)自定义FullScreenLinearLayout

public class FullScreenLinearLayout extends LinearLayout {
    private int[] mInsets = new int[4];

    public FullScreenLinearLayout(@NonNull Context context) {
        super(context);
    }

    public FullScreenLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public FullScreenLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public final int[] getInsets() {
        return mInsets;
    }

    @Override
    protected final boolean fitSystemWindows(Rect insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // Intentionally do not modify the bottom inset. For some reason,
            // if the bottom inset is modified, window resizing stops working.
            // TODO: Figure out why.

            mInsets[0] = insets.left;
            mInsets[1] = insets.top;
            mInsets[2] = insets.right;

            insets.left = 0;
            insets.top = 0;
            insets.right = 0;
        }

        return super.fitSystemWindows(insets);
    }

    /*
    @Override
    public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            mInsets[0] = insets.getSystemWindowInsetLeft();
            mInsets[1] = insets.getSystemWindowInsetTop();
            mInsets[2] = insets.getSystemWindowInsetRight();
            return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,
                    insets.getSystemWindowInsetBottom()));
        } else {
            return insets;
        }
    }
    */
}

(2)根布局FullScreenLinearLayout设置属性

<me.yezhou.lib.ui_widget.layout.FullScreenLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    >
上一篇 Android内容被底部虚拟导航栏遮挡解决
下一篇 Android RecycleView全部item倒计时的高效实现