Question: I'm creating a registration screen for my game. I implemented textfields and input is getting correctly. But when I click elsewhere after text is entered, the keyboard stays visible and does not hide automatically, even when a new screen is loaded. Is there any listener methods for hiding the keyboard?

Right now I did a workaround by calling the `setOnscreenKeyboardVisible(false)` in the sign up and sign in buttons. But I want the keyboard to hide right when it is unfocussed. Is it possible?

**UPDATE:**

Actually I thought when I click elsewhere the textfield focus changed automatically but that's not the case. The cursor keeps blinking even after the keyboard is hidden explicitly. I edited the correct answer to include this.

Answer: 
Try this:

```
@Override
public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
    super.keyboardFocusChanged(event, actor, focused);
    if (!focused)
        setOnscreenKeyboardVisible(false);
}

```

Otherwise you could go for a better work around. You place a big clickable transparent actor behind everything. When you click anywhere next to your buttons, textfields, etc this field will be triggered and you can get rid of your keyboard ;).

**EDIT:**

The textfield will remain focused even after this, so the cursor will keep blinking and we don't want that. As mentioned here:

<http://www.java2s.com/Code/Flash-Flex-ActionScript/TextField/ToremovefocusfromatextfieldyoushouldassignStagefocusthenullvalue.htm>

you should also unfocus the stage along with hiding the keyboard.

```
stage.unfocusAll()

```
Menno Gouw's answer is correct and is probably the way to go in most cases, but just in case someone runs into my problem where that solution might distort the positioning of other actors I thought I'd post how I solved it.

First Create an "invisible" button:

```
ImageButtonStyle style = new ImageButtonStyle();
style.up = null;
style.down = null;
cancelFocusButton = new ImageButton(style);

```

Second, add your listener to the invisible button:

```
cancelFocusButton.addListener(new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
        Gdx.input.setOnscreenKeyboardVisible(false);
        stage.unfocusAll();
    }
});

```

Third, add this button to a stack together with the table that holds all your other actors (Textfields, labels, button etc):

```
Stack stack = new Stack();
stack.addActor(cancelFocusButton);
stack.addActor(tempTable);

```

Lastly add your stack to your "main table" (in my case the ContentTable inside the dialog):

```
getContentTable().add(stack).expand().fill();

```