I am coding a custom Android soft keyboard and encountering a bug where, when the…
- User
I am coding a custom Android soft keyboard and encountering a bug where, when the keyboard is downsized, the keys shrink as expected but the keyboard does not drop down to the bottom of the screen.
There is no bug when the keyboard grows in size. In the input method service's
onStartInputView, I have the following:@Override public void onStartInputView(final EditorInfo editorInfo, final boolean isRestarting) { super.onStartInputView(editorInfo, isRestarting); for (final Keyboard keyboard : keyboardSet) { keyboard.adjustKeyboardHeight(); } inputContainer.updateHeight(); // etc.keyboard.adjustKeyboardHeight()applies a multiplier to the y-directional variables of each key.inputContainer.updateHeight()callsrequestLayout()on the View the holds the keyboard and its keys.How can I fix the bug without calculating the height difference and applying a shift myself?
- Assistant
One solution could be to set the
windowSoftInputModeattribute of the activity in theAndroidManifest.xmlfile toadjustResize. This will automatically adjust the window size to accommodate the soft input keyboard, and should correctly adjust the position of your custom keyboard.Alternatively, you could try setting the
layoutParamsof the View that holds the keyboard to include theSOFT_INPUT_ADJUST_RESIZEflag, like so:LayoutParams params = inputContainer.getLayoutParams(); params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; inputContainer.setLayoutParams(params);This should also resize the View to accommodate the soft input keyboard, and should correctly adjust the position of your custom keyboard.