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

一般用法

  • 设置属性:
 android:windowSoftInputMode="stateVisible|adjustResize"
 android:fitsSystemWindows="true"

以上做法会导致toolbar向下平移了statusbar的高度,也就是说statusbar是全白的。。

解决办法:

  1. 自定义CustomInsetsFrameLayout
public class CustomInsetsFrameLayout extends FrameLayout{
    private int[] mInsets = new int[4];

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

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

    public CustomInsetsFrameLayout(@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);
    }
}
  1. 设置属性
 android:windowSoftInputMode="stateVisible|adjustResize"
 android:fitsSystemWindows="true"

完美适配!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容