1
votes

I have an Android application with a text field. When I start typing, the keyboard pushes the background image upwards.

I want the image to stay in place and the keyboard to cover it, instead.

Changing the layout to BoxLayout or BorderLayout does not have any effect on the position of the background image, neither does changing scrollable:

container.setScrollableY(false);
form.setScrollableY(false);

How would I achieve keeping the image in place?

One other thing I was unable to figure out was accessing the form with the cursor already in the TextField and the keyboard visible, setting:

textField.requestFocus();

But that also does not have the desired effect.

Any help would be appreciated.

enter image description here

2

2 Answers

2
votes

In addition to Shai's answer, you could try placing the TextField parent container in the north of a BorderLayout container and the image container in the center. This could somehow enforce the keyboard to slide over the image in the center.

To answer the part of TextField editing when the form is shown, add below to the TextField form

form.setEditOnShow(textField);

If you already have some text in the TextField, you might want to set below to place the cursor at the end:

CN.callSerially(() -> {
    textField.setCursorPosition(textField.getText().length());
    form.repaint(); // optional form repainting
});
1
votes

Text fields must be in a scrollable parent.

If the image and the text field are in the same container and the text field is above the image you might get something closer to the second image. On iOS the scroll region is increased to accommodate the virtual keyboard, on Android the screen is resized to accommodate it.

This can lead to nuanced behavior difference as the size of the screen adapts.