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

问题描述

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

解决方法

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

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

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

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

解决办法:

(1)自定义FullScreenLinearLayout

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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设置属性

1
2
3
4
5
6
<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"
>

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :