Skip to content
The Chat Archive
gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

I am coding a custom Android soft keyboard and encountering a bug where, when the…

  1. 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() calls requestLayout()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?

  2. Assistant

    One solution could be to set the windowSoftInputMode attribute of the activity in the AndroidManifest.xml file to adjustResize. 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 layoutParams of the View that holds the keyboard to include the SOFT_INPUT_ADJUST_RESIZE flag, 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.