Due to the location of my 2 text boxes towards the bottom of the screen, I have developed the following code to shift my text boxes to a new position when either one is touched (so as to prevent keyboard overlap):
local textField = native.newTextField( display.contentCenterX, display.contentCenterY + 60, 200, 40 ) textField.placeholder = "Email" textField.isEditable = true local textField2 = native.newTextField( display.contentCenterX, display.contentCenterY + 110, 200, 40 ) textField2.placeholder = "Password" textField2.isEditable = true --function to handle events local function touchListener(oEvent) local oTextField = oEvent.target if "began" == oEvent.phase then textField.y = display.contentCenterY - 120 textField2.y = display.contentCenterY - 70 myText.y = 55 local button2 = widget.newButton { x = display.contentCenterX, y = display.contentCenterY - 20, id = "loginbutton", defaultFile = "buttonDefault.png", font = "Georgia", labelColor = { default={ 1, 1, 1 } }, label = "Login" } elseif "editing" == oEvent.phase then elseif "submitted" == oEvent.phase then textField.y = display.contentCenterY - 120 textField2.y = display.contentCenterY - 70 myText.y = 55 button2.isVisible = false native.setKeyboardFocus( nil ) --hides keyboard elseif "ended" == oEvent.phase then textField.y = display.contentCenterY + 60 textField2.y = display.contentCenterY + 110 myText.y = display.contentCenterY - 3 end end textField:addEventListener( "userInput", touchListener )
Could some body please assist me in how I might go about detecting with Lua when the keyboard is not visible, so that if a user exits the text box (either by pressing away or by pressing the “back” feature on the Android) I can do it so the text boxes go back to there original positions?
Thank you for your help in advance!