Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8248349

[Android] Hide keyboard when user taps outside a TextInputControl

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx15
    • javafx
    • None

      The soft keyboard hides when a TextInputControl loses focus. This works for most cases, but when focus moves from one TextInputControl to another, the keyboard hides and then shows itself.

      Native android apps hide the keyboard when a users taps anywhere on the scene which is not a TextInputControl.

      For this change, the native method `hideSoftwareKeyboard` needs to be made accessible to Scene.

      A MOUSE_CLICKED event filter needs to be added to Scene and focus listeners from both TextFieldSkinAndroid and TextAreaSkinAndroid needs to be removed.

      Expected change:

      ```
      scene.addEventFilter(MouseEvent.MOUSE_CLICKED, evt -> {
              if (!containsTextInputControlInHierarchy(evt.getPickResult().getIntersectedNode())) {
                  hideSoftwareKeyboard();
             }
      });

      ...

      public static boolean containsTextInputControlInHierarchy(Node node) {
          while (node != null) {
              if (node instanceof TextInputControl) {
                  return true;
              }
              node = node.getParent();
          }
          return false;
      }
      ```

            abagarwal Abhinay Agarwal
            abagarwal Abhinay Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: