I have read many threads, but I was not very clear. How to capture the closing of the keyboard?
Asked
Active
Viewed 7,124 times
1 Answers
3
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);
}
To see how to implement , check this answer https://stackoverflow.com/a/7423586/864955
-
Because is not a hardware keyboard, but it is the soft keyboard – Gioacchino Del Prete Jan 16 '12 at 15:41
-
I have added the Work around to detect if the virtual key board / soft keyboard is shown/hidden. Have you tried that? – rfsk2010 Jan 16 '12 at 15:43
-
In what way? I also added android:configChanges="keyboardHidden|keyboard" in the manifest. – Gioacchino Del Prete Jan 16 '12 at 15:47
-
I have edited the answer to show how to implement it. It links to another answer. please let me know if it works – rfsk2010 Jan 16 '12 at 15:52
-
1The solution in this thread http://stackoverflow.com/questions/2150078/android-is-software-keyboard-shown – Gioacchino Del Prete Jan 16 '12 at 16:08