stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
    TextField.TextFieldStyle style = new TextField.TextFieldStyle();
    style.font = font;
    style.fontColor = Color.BLACK;
    style.cursor =
    style.selection = new Image(new Texture("core/assets/skin/textfield-big.png")).getDrawable();
    style.background = new Image(new Texture("core/assets/skin/textfield-big.png")).getDrawable();
    text = new TextField("Name", style);
    text.setPosition(50, 50);

When I draw my stage, I can see my textfield, but when I hover it, my cursor doesn't change, and when I focus I can't see that blinking " | " at all, like normal textfields have.

What did I do wrong? Is it because style.cursor is null? If yes, how can I set it to the default cursor that libgdx uses?


This is an old issue, but for future scrollers: A lot of people suggest that you load up a seperate drawable, but to me that feels like overkill for the one character. Instead, what I do (as of today) is use a Pixmap to get a black rectangle the size of the '|' character, then feed that in as the drawable for the cursor image.

Similar logic also works for the selection variable, which you may be interested in changing as well.

Label oneCharSizeCalibrationThrowAway = new Label("|", yourLabelStyle);
Pixmap cursorColor = new Pixmap((int) oneCharSizeCalibrationThrowAway.getWidth(),
            (int) largeSizeCalibrationThrowAway.getHeight(),

yourTextFieldStyle.cursor = new Image(new Texture(cursorColor)).getDrawable();
| improve this answer | |
  • \$\begingroup\$ You saved my day \$\endgroup\$ – salih kallai Sep 1 '19 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.