Android在全屏下ScrollView包裹EditText软键盘弹出后,ScrollView无法滚动
问题描述
在全屏下ScrollView包裹EditText软键盘弹出后,ScrollView无法滚动,设置adjustResize无效
解决方法
在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"
>
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/android-scrollview-cannot-scroll-when-the-edittext-soft-keyboard-pops-up-in-full-screen/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Android在全屏下ScrollView包裹EditText软键盘弹出后,ScrollView无法滚动
问题描述
在全屏下ScrollView包裹EditText软键盘弹出后,ScrollView无法滚动,设置adjustResize无效
解决方法
参考:https://stackoverflow.com/questions/210……
文章目录
关闭
共有 0 条评论