vedi0boy
vedi0boy

Reputation: 1040

LibGDX: Moving text field so it is visible when typing with on-screen keyboard

I am currently making a login system for a game I am making. I have a "Username" TextField and a "Password" TextField. When using a mobile device such as Android, I am required to use an on screen keyboard. The thing is that the keyboard blocks the TextField box and I can't see it any more when I'm typing. Is there a way to move the TextField while the On-Screen Keyboard is being shown?

I have tried several ways but where I am stuck is that there is no way to detect whether the keyboard is on the screen or not. Also, using a pop-up text entering dialog is out of the question since I have a password field and there is no password option for those.

Thanks in advance!

Upvotes: 2

Views: 963

Answers (1)

Neerkoli
Neerkoli

Reputation: 2695

So late to answer, but if helps anyone.

Add a FocusListener() to the TextField and thus you can listen to the event when the TextField is focused (clicked).

Change the camera's y position to a number that is around half the screen height by calling:

camera.position.set(x, y, z);
camera.update();

This will move the screen up and you can now view the things that were blocked earlier by the keyboard.

Upvotes: 2

Related Questions