Android(安卓)ScrollView包裹EditText 软键盘弹出后,ScrollView 无法滚动
16lz
2021-12-10
一般用法
- 设置属性:
android:windowSoftInputMode="stateVisible|adjustResize" android:fitsSystemWindows="true"
以上做法会导致toolbar向下平移了statusbar的高度,也就是说statusbar是全白的。。
解决办法:
- 自定义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); }}
- 设置属性
android:windowSoftInputMode="stateVisible|adjustResize" android:fitsSystemWindows="true"
完美适配!
更多相关文章
- Android2.2 API 中文文档系列(2) —— EditText
- Android(安卓)TabLayout 浅显总结
- Android(安卓)关于获取摄像头帧数据
- Android(安卓)WebView的使用(一)
- 文章标题
- android anim 动画效果
- android Log.isLoggable方法的使用
- 自己编写Android手电筒,支持5.0
- android音频、视频、拍照基础操作