I have an EditText and want to give it more lines when the keyboard appears. So i am looking for something like a "OnKeyboardAppearsListener" but can't find it. I think it must exist, but perhaps in a different way...
Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.
The soft keyboard (also called the onscreen keyboard) is the main input method on Android devices, and almost every Android developer needs to work with this component at some point.
You have to @Override onConfigurationChanged
to be able to handle runtime changes:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware or on-screen keyboard is available
if (newConfig.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO) {
Toast.makeText(this, "Keyboard visible", Toast.LENGTH_SHORT).show();
} else if (newConfig.keyboardHidden == Configuration.KEYBOARDHIDDEN_YES) {
Toast.makeText(this, "Keyboard hidden", Toast.LENGTH_SHORT).show();
}
}
Example taken from here. Take a look here for keyboard related (among others) fields you might want to use.
Edit (RivieraKid): Changed to take account of hard or on-screen keyboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With