安卓加载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不用设置什么
希望能帮到各位