Type Function Library native.* Return value TextBox Revision Current Public Release (2016.2830) Keywords text box, text input, native text See also native.newTextField() native.setKeyboardFocus() userInput events
Creates a scrollable, multi-line text box for text input. For
By default, the content of text boxes is not editable. Set the object.isEditable property to
true to make the content editable.
Native text boxes can listen for userInput events (see example).
"\n" to start text on a new line. Text will automatically wrap to the next line if it's too long.
Native text boxes are not part of the OpenGL canvas and do not obey the display object hierarchy, so they will always appear in front of normal display objects including images, text, and vector objects. However, native text boxes can be "inserted" (object:insert()) into Corona display groups and they will move in unison with that group.
Presentation of native controls in the Corona Simulator can only be an approximation of the actual device. Always test on a device and assume that the behavior/appearance on devices is correct.
To remove a native text box from the display, use
The native.setKeyboardFocus() API is used to show and hide the keyboard used for text input (applies to device and Xcode Simulator only).
On Android, due to the fact that Corona runs on multiple threads, getting the
.text value of a TextBox immediately after setting it will not return the correct value. This action should be performed following a short timer or during the next time step.
native.newTextBox( centerX, centerY, width, height )
Numbers. The x and y coordinates that correspond to the center of the text box.
local function inputListener( event ) if event.phase == "began" then -- user begins editing textBox print( event.text ) elseif event.phase == "ended" then -- do something with textBox text print( event.target.text ) elseif event.phase == "editing" then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local textBox = native.newTextBox( 200, 200, 280, 140 ) textBox.text = "This is line 1.\nAnd this is line2" textBox.isEditable = true textBox:addEventListener( "userInput", inputListener )