您的位置:首页 > 移动开发 > Android开发

android-获取虚拟键盘的高度(让虚拟键盘顶部和弹出框底部贴着)

2016-01-04 16:34 471 查看
》获取虚拟键盘的高度

View
mYourView;

int mVisibleHeight;
boolean mIsKeyboardShow;
protected void onCreate(Bundle savedInstanceState) {
...
mYourView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getKeyboardHeight();
}
});
...
}
private void getKeyboardHeight() {
Rect r = new Rect();
mYourView.getWindowVisibleDisplayFrame(r);
int visibleHeight = r.height();
if (mVisibleHeight == 0) {
mVisibleHeight = visibleHeight;
return;
}
if (mVisibleHeight == visibleHeight) {
return;
}
mVisibleHeight = visibleHeight;
// Magic is here
if (/* compare the visiable height to others */) {
mIsKeyboardShow = true;
} else {
mIsKeyboardShow = false;
}
}

》有待验证,正在进行中。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: