Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show keyboard in Libgdx

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!

like image 225
Araw Avatar asked Feb 02 '26 01:02

Araw


1 Answers

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);

like image 134
nEx.Software Avatar answered Feb 03 '26 17:02

nEx.Software



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!