本文主要是介绍android-获取虚拟键盘的高度(让虚拟键盘顶部和弹出框底部贴着),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
》获取虚拟键盘的高度
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;
}
}
》有待验证,正在进行中。。。
这篇关于android-获取虚拟键盘的高度(让虚拟键盘顶部和弹出框底部贴着)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!