android 全屏 webview 加载的h5的输入框,被键盘遮挡的解决
16lz
2021-12-04
安卓加载h5 ,h5界面有输入框 ,安卓键盘会被遮住 。
我是在全屏的状态下 这样设置有效(亲测)
class CustomLinearLayout: LinearLayout { constructor(context: Context?): super(context) { } constructor(context: Context?, attrs: AttributeSet?): super(context, attrs) { } constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr) { } override fun fitSystemWindows(insets: Rect): Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { insets.left = 0 insets.top = 0 insets.right = 0 } return super.fitSystemWindows(insets) } @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { super.onApplyWindowInsets( insets.replaceSystemWindowInsets( 0, 0, 0, insets.systemWindowInsetBottom ) ) } else { insets } }}
此处是ktlion代码
public class CustomLinearLayout extends LinearLayout { public CustomLinearLayout(Context context) { super(context); } public CustomLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected boolean fitSystemWindows(Rect insets) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { insets.left = 0; insets.top = 0; insets.right = 0; } return super.fitSystemWindows(insets); } @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Override public WindowInsets onApplyWindowInsets(WindowInsets insets) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom())); } else { return insets; } }}
此处是java代码 我都贴出来 害怕有些人看不懂kotlin
更改布局的第一个节点 替换为自定义的类
AndroidManifest不用设置什么
希望能帮到各位
更多相关文章
- Android串口开发,基于官方的android-serialport-api增加支持设置
- Android(安卓)Window PhoneWindow DecorView
- Android成长(二)——两个页面交互
- android手机打电话代码分析
- Android(安卓)WIndow,WindowManager简单介绍
- android:EditText属性/去边框
- Android(安卓)Platform 3.0 SDK和Eclipse ADT安装记录三
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- Android开发之dagger.android--Activity