|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.badlogic.gdx.scenes.scene2d.ui.TextField
public class TextField
A single-line text field.
Clipboard
interface. Currently there
are two standard implementations, one for the desktop and one for Android. The later is a stub, as copy & pasting on Android is
not supported yet. To set your own Clipboard implementation use the setClipboard(Clipboard)
method.
TextField.OnscreenKeyboard
implementation responsible for
displaying a softkeyboard and piping all key events generated by the keyboard to the TextField. There are two standard
implementations, one for the desktop and one for Android. The former is a stub, as a softkeyboard is not needed on the desktop.
The Android TextField.OnscreenKeyboard
implementation will bring up the default IME. If you want to set your own
TextField.OnscreenKeyboard
for a TextField use the setOnscreenKeyboard(OnscreenKeyboard)
method. The OnscreenKeyboard
allows you to dynamically show and hide it, e.g. based on a key event for the return key.
TextField.TextFieldListener
. This listener will be invoked after a new character
was added or removed to and from the TextField. This allows you to perform input checks or dynamically hide the
OnscreenKeyboard.
Button#setPrefSize(int, int)
to
programmatically change the size to your liking. In case the width and height you set are to small for the contained text, the
TextField will clip the characters based on the current cursor position.
Widget
displaying a background NinePatch
, the current text via a BitmapFont
and
Color
, a cursor via a NinePatch
as well as the current selection via a TextureRegion
that is stretched
over the entire selection. The style is defined via an instance of TextField.TextFieldStyle
, which can be either done
programmatically or via a Skin
.
A TextField's style definition in a skin XML file should look like this:
<textfield name="name"
font="fontName"
fontColor="fontColor"
cursor="cursorPatch"
selection="selectionRegion"
background="backgroundPatch"/>
name
attribute defines the name of the style which you can later use with
Skin#newTextField(String, float, String)
.font
attribute references a BitmapFont
by name, to be used to render the text in the text fieldfontColor
attribute references a Color
by name, to be used to render the text on the text fieldcursorPatch
attribute references a NinePatch
by name, to be used to render the text field's cursor
selectionRegion
attribute references a TextureRegion
by name, to be used to highlight the text
field's selectionbackgroundPatch
attribute references a NinePatch
by name, to be used as the text field's
background
Nested Class Summary | |
---|---|
static class |
TextField.DefaultOnscreenKeyboard
The default TextField.OnscreenKeyboard used by all TextField instances. |
static interface |
TextField.OnscreenKeyboard
An interface for onscreen keyboards. |
static interface |
TextField.TextFieldListener
Interface for listening to typed characters. |
static class |
TextField.TextFieldStyle
Defines a text field's style, see TextField |
Field Summary |
---|
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget |
---|
invalidated |
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor |
---|
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, touchable, visible, width, x, y |
Constructor Summary | |
---|---|
TextField(Skin skin)
|
|
TextField(java.lang.String text,
Skin skin)
|
|
TextField(java.lang.String text,
TextField.TextFieldStyle style)
|
|
TextField(java.lang.String text,
TextField.TextFieldStyle style,
java.lang.String name)
Creates a new Textfield. |
|
TextField(TextField.TextFieldStyle style)
|
Method Summary | |
---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
TextField.OnscreenKeyboard |
getOnscreenKeyboard()
Returns the currently used TextField.OnscreenKeyboard . |
float |
getPrefHeight()
|
float |
getPrefWidth()
|
java.lang.String |
getText()
|
Actor |
hit(float x,
float y)
|
boolean |
keyDown(int keycode)
|
boolean |
keyTyped(char character)
|
void |
layout()
Positions and sizes each child of this actor. |
void |
setClipboard(Clipboard clipboard)
Sets the Clipboard implementation this TextField uses. |
void |
setOnscreenKeyboard(TextField.OnscreenKeyboard keyboard)
Sets the TextField.OnscreenKeyboard to be used by this textfield |
void |
setStyle(TextField.TextFieldStyle style)
Sets the style of this widget. |
void |
setText(java.lang.String text)
Sets the text of this text field. |
void |
setTextFieldListener(TextField.TextFieldListener listener)
Sets the TextField.TextFieldListener |
boolean |
touchDown(float x,
float y,
int pointer)
|
void |
touchDragged(float x,
float y,
int pointer)
|
void |
touchUp(float x,
float y,
int pointer)
|
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget |
---|
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy |
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor |
---|
act, action, clearActions, isMarkedToRemove, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchMoved |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TextField(Skin skin)
public TextField(java.lang.String text, Skin skin)
public TextField(TextField.TextFieldStyle style)
public TextField(java.lang.String text, TextField.TextFieldStyle style)
public TextField(java.lang.String text, TextField.TextFieldStyle style, java.lang.String name)
style
- the TextField.TextFieldStyle
prefWidth
- the (preferred) widthname
- the nameMethod Detail |
---|
public void setStyle(TextField.TextFieldStyle style)
style
- public void layout()
Layout
Layout.invalidate()
is
called.
public void draw(SpriteBatch batch, float parentAlpha)
Actor
FadeIn
and
other Actions to have an effect even if they are only set on the parent of the Actor.
draw
in class Actor
batch
- the spritebatch to render withparentAlpha
- the parent's alpha value.public boolean touchDown(float x, float y, int pointer)
touchDown
in class Actor
public void touchUp(float x, float y, int pointer)
touchUp
in class Actor
public void touchDragged(float x, float y, int pointer)
touchDragged
in class Actor
public boolean keyDown(int keycode)
keyDown
in class Actor
public boolean keyTyped(char character)
keyTyped
in class Actor
public Actor hit(float x, float y)
hit
in class Widget
public void setTextFieldListener(TextField.TextFieldListener listener)
TextField.TextFieldListener
listener
- the listener or nullpublic void setText(java.lang.String text)
text
- the textpublic java.lang.String getText()
public float getPrefWidth()
public float getPrefHeight()
public TextField.OnscreenKeyboard getOnscreenKeyboard()
TextField.OnscreenKeyboard
. TextField
instances use the TextField.DefaultOnscreenKeyboard
by
default.
public void setOnscreenKeyboard(TextField.OnscreenKeyboard keyboard)
TextField.OnscreenKeyboard
to be used by this textfield
keyboard
- the OnscreenKeyboardpublic void setClipboard(Clipboard clipboard)
Clipboard
implementation this TextField uses.
clipboard
- the Clipboard
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |