输入法遮挡问题
解决输入法遮挡的问题 基本上有两种
adjustResize + ScrollView
adjustPan
adjustPan会把页面整体上推
adjustResize则是缩放可调整页面 所以要和ScrollView配合 但是如果界面设成全屏模式就不会生效
具体什么情况下失效,我没怎么验证。建议直接使用 adjustPan,就肯定失效了。
解决方法
方法1:获取界面可用高度,如果软键盘弹起后,Activity的xml布局可用高度需要减去键盘高度
方法2:增加一个白屏布局,获取高度,设置高度,更靠谱好用
ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
// ime // 软键盘
Insets imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime());
int height = imeInsets.bottom;
int top = imeInsets.top;
YZJLog.d("im-baseFold", "imeInsets height = " + height + ", top = " + top);
Insets navigationBars = insets.getInsets(WindowInsetsCompat.Type.navigationBars());
YZJLog.d("im-baseFold", "navigationBars height = " + navigationBars.bottom + ", top = " + navigationBars.top);
try {
height = height - navigationBars.bottom;
if (list != null && list.size() > 0) {
for (IWindowInsetsListener windowInsetsListener : list) {
windowInsetsListener.onKeyboardShown(height > 0 ? height : 0);
}
}
} catch (Exception e) {
}
return insets;
}
});
参考:
https://www.ngui.cc/el/1482026.html?action=onClick
http://www.manongjc.com/detail/54-nvnxfsozfsoxpuy.html
WindowInsetsCompat的浅识
https://blog.csdn.net/SOHU_TECH/article/details/126397570