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

```
I needed to do the same thing and went for an extremely simple solution in the end and it seems to work well.

I created my own StageExtension class that extends Stage (for other reasons), but within this I simply override the touchDown method adding 2 lines;

```
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    super.unfocusAll();
    Gdx.input.setOnscreenKeyboardVisible(false);
    return super.touchDown(screenX, screenY, pointer, button);
}

```

You can of course add some simple checks in there to match your needs, but this works perfectly for me.