本文介绍了键盘隐藏事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看了很多线程,但我也不是很清楚。如何捕捉键盘的关闭?
I have read many threads, but I was not very clear. How to capture the closing of the keyboard?
推荐答案
您可以执行以下操作来检测,如果硬件键盘显示/隐藏
you can do the following to detect if the hardware key board is shown/hidden
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// if a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
}
}
您可以做以下的解决方法以检测是否虚拟键盘显示/隐藏
you can do the following Work around to detect if the virtual key board is shown/hidden
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
final int actualHeight = getHeight();
if (actualHeight > proposedheight){
// Keyboard is shown
} else {
// Keyboard is hidden
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
要了解如何执行,检查这个答案 http://stackoverflow.com/a/7423586/864955
To see how to implement , check this answer http://stackoverflow.com/a/7423586/864955
这篇关于键盘隐藏事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!