Android(安卓)软键盘弹出与关闭监听
16lz
2021-12-23
private void listenerSoftInput() {
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // 如果高度差超过100像素,就很有可能是有软键盘...
scrollToBottom();
} else {
}
}
});
}
//scrollview滑到底部
protected void scrollToBottom() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
scrollview.fullScroll(View.FOCUS_DOWN);
}
}, 100);
}
更多相关文章
- Android(安卓)Studio点击空白处收起软键盘
- android中隐藏以及显示软键盘代码
- android 截获键盘事件
- Android(安卓)键盘弹出与隐藏
- Android仿iOS时间选择器
- Android(安卓)点击按钮隐藏键盘
- android 监听判断软键盘的弹出、隐藏状态
- android .9 图片的全能适配方法
- android软键盘的显示与隐藏