I am trying to show the keyboard on a android device when a textfield is clicked in LibGdx. But as far as I can see have to detect when the textfield is clicked manually and then show the keyboard by calling Gdx.input.setOnscreenKeyboardVisible(true)?
This is the code I have so far:
textfield= new TextField("", skin);
textfield.setSize(300, 50);
textfield.setPosition((SCREEN.WIDTH/2) - textfield.getWidth()/2, 0);
//Gdx.input.setOnscreenKeyboardVisible(true);
//Gdx.input.getTextInput(this, "SOME TITLE" "TEXT");
textfield.setTextFieldListener(new TextFieldListener()
{
@Override
public void keyTyped(TextField textField, char key)
{
if (key == '\n')
{
textField.getOnscreenKeyboard().show(false);
}
}
});
Thanks for any help!
Moved from comment on original post (and edited to be more answer-like):
The keyboard is normally shown automatically when a text field gains focus or is touched. You shouldn't have to do it manually. This requires the stage to be registered as the input processor via this call:
Gdx.input.setInputProcessor(stage);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With