# LibGDX Textfield has no pointer cursor or blinking on hover / focus

    stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
Gdx.input.setInputProcessor(stage);
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.setWidth(500);
text.setHeight(37);
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(),
Pixmap.Format.RGB888);
cursorColor.setColor(Color.BLACK);
cursorColor.fill();

yourTextFieldStyle.cursor = new Image(new Texture(cursorColor)).getDrawable();

• You saved my day – salih kallai Sep 1 '19 at 10:14