如何监听软键盘的显示与隐藏
2016-03-30 19:15
387 查看
parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView()
.getHeight();
int heightDifference = screenHeight - (r.bottom);
if (heightDifference > 200) {
isKeyBoardVisible = true;
// changeKeyboardHeight(heightDifference);
} else {
isKeyBoardVisible = false;
}
}
});
//parentLayout为布局父控件,因为当软件盘显示和隐藏时当windowSoftInputMode为adjustResize时parentLayout会调
//用onsizechange方法,因此对布局树进行监听可以判读出软件盘的显示与隐藏
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView()
.getHeight();
int heightDifference = screenHeight - (r.bottom);
if (heightDifference > 200) {
isKeyBoardVisible = true;
// changeKeyboardHeight(heightDifference);
} else {
isKeyBoardVisible = false;
}
}
});
//parentLayout为布局父控件,因为当软件盘显示和隐藏时当windowSoftInputMode为adjustResize时parentLayout会调
//用onsizechange方法,因此对布局树进行监听可以判读出软件盘的显示与隐藏
相关文章推荐
- 第七课作业
- iOS storyboard中设置TableView的headerview 和 footerview
- C++ 多继承
- 结构体--点坐标结构体
- 算法之插入排序
- IOS学习之——背景平铺
- android 屏幕旋转180度
- WebService CXF学习笔记
- 【BZOJ-2733】永无乡 Splay+启发式合并
- 怎样找对还有一半--第一章 品行与择偶关系
- debian安装后sudo命令不能用的解决方法
- UIPageViewController用法
- 中文分词学习总结
- 循环的数学应用
- POJ2229 Sumsets(DP)
- 小明的筷子java
- HDU 5651 xiaoxin juju needs help
- codeforces 626C - Block Towers
- Github 网页上 更新 Fork别人的 Repository
- POJ-1274-The Perfect Stall【二分图最大匹配】【模板题】