Copy link to clipboard
Copied
Hello all,
I've been scratching my head with this for a while now and think I need to ask for help.
I have a TextField which is set to TextFieldType.INPUT. On Apple devices, when a user clicks on this text field, it focuses in on the text field like we'd expect it to, however on Android the soft keyboard appears over the text field making input awkward.
What I've tried so far:
Explicitly setting: <softKeyboardBehavior>pan</softKeyboardBehavior>
&
var locToGlob:Point = _textInput.localToGlobal(0,0);
this._textInput.softKeyboardInputAreaOfInterest = new Rectangle(locToGlob.x,locToGlob.y,_textInput.width ,_textInput.height);
But it just seems to completely ignore softKeyboardInputAreaOfInterest.
Does anybody know why this might be? I'm using AIR 4.0.
Thank you in advance for any help anyone may be able to offer.
Copy link to clipboard
Copied
Hi Andrew,
I haven't looked into this in a long while, so things may have changed since, but the last time I delt with this, I ended up disabling sofkeyboard behavior on both platforms, and handling my own offsetting ( via a tween ) of the Sprite containing the text field, so that the editable textfield would wind up above the keyboard.
On both platforms ( iOS + Android ), add the following in the manifest:
<softKeyboardBehavior>none</softKeyboardBehavior> |
Here are the main bits code I used to handle this, to give you an idea. Note: _softKeyboardDisplacer is my own tween class, but this would work with the regular Tween class as well.
private var _searchTF:TextField; private var _softKeyboardDisplacer:SimpleTween; // displaces _categoriesListSP when the soft keyboard is called private var _softKeyboard:Boolean; // indicates if the soft keyboard is currently on or not private function initSearchField():void { // search input text field var searchTFT:TextFormat = new TextFormat(Boolean(CONFIG::IOS) ? "Verdana" : "VerdanaFont", 30 * SM.UI_SCALE_800, 0x000000, true); // Note: "Verdana" is one of the system fonts on iOS devices. Using the embedded version doesn't work for input text fields on iOS. _searchTF = Assets.getInputTF(0.7 * SM.stageWidth, NaN, searchTFT);
with( _searchTF ) { addEventListener(FocusEvent.FOCUS_IN, onSoftKeyboardActivate, false, 0, true); addEventListener(FocusEvent.FOCUS_OUT, onSoftKeyboardDeactivate, false, 0, true); } Align.align(_dictionaryCenter, _searchTF, Align.CENTER_VERT, 0, Align.CENTER_HORIZ, 0); _categoriesListSP.addChild( _searchTF );
// Add soft keyboard listener _softKeyboardDisplacer = new SimpleTween(_categoriesListSP, "y", Interp.cubic, 0, 1, 0.3, true); _softKeyboardDisplacer.addEventListener(SimpleTweenEvent.MOTION_CHANGE, onSoftKeyboardDisplacerMotionChange, false, 0, true); } private function onSoftKeyboardActivate(evt:FocusEvent):void { _softKeyboard = true; _searchSuccessful = false; // open soft keyboard evt.target.requestSoftKeyboard(); // needed on Android, but doesn't work on iOS stage.focus = evt.target as InteractiveObject; var searchTFBounds:Rectangle = _searchTF.getBounds(stage);
var finishY:Number = _categoriesListSP.y - ( (searchTFBounds.bottom - SM.stageHeight_d2 ) + SM.stageHeight * 0.05 ); _softKeyboardDisplacer.stop(); _softKeyboardDisplacer.begin = _categoriesListSP.y; _softKeyboardDisplacer.finish = finishY; _softKeyboardDisplacer.start(); }
private function onSoftKeyboardDeactivate(evt:FocusEvent):void { _softKeyboard = false; // do the search lookFor( _searchTF.text ); if (!_searchSuccessful) { _softKeyboardDisplacer.stop(); _softKeyboardDisplacer.begin = _categoriesListSP.y; _softKeyboardDisplacer.finish = 0; _softKeyboardDisplacer.start(); } } private function toggleSoftKeyboard():void { if (!_softKeyboard) { // note: no need to go to the home page, bc _softKeyboardDisplacer will go there as soon as //the soft keyboard is activated (via onSoftKeyboardActivate() )
// Below: requestSoftKeyboard() is needed on Android to bring-up soft keyboard, // but doesn't work on iOS ( hence the redundant stage.focus = _searchTF, below ) _searchTF.requestSoftKeyboard(); stage.focus = _searchTF; } else closeSoftKeyboard(); }
private function closeSoftKeyboard():void { stage.focus = null; // this will close the soft keyboard _softKeyboard = false; } |
Cheers.
Copy link to clipboard
Copied
Hi. I am using the latest Air SDK and also experiencing the exact same issue using StageWebView. The keyboard always overlays the content...
Have you found a fix to this yet? I have also played with various renderModes but nothing works. softKeyboardBehavior pans perfectly on iOS ?
Hope someone can help,
Cheers
Copy link to clipboard
Copied
Linking a possible solution here for anyone ending up in this post: Re: Softkeyboard pan issue in AIR for Android