Get the height of the softkeyboard in Adobe AIR Mobile
Asked Answered
Z

1

9

We're trying to plan out a mobile AIR application that will deploy to both Android and iOS. One of the screens our design team has returned is a fullscreen text editor that runs from the top of the screen to the keyboard. I obviously cannot do this if I cannot grab the height of the keyboard programatically. Is there a way to do this?

I know that it is possible in iOS and it appears to be impossible in Android. I have no issue creating an ANE to do it, but I would rather avoid it if the data is already available in AIR. Alternatively, I could just assume that the keyboard is 1/2 the size of the screen and this would work, for the most part, on iOS just fine.

In short, is getting the height of the softkeyboard possible in AIR?

Zug answered 13/12, 2012 at 23:54 Comment(2)
Good question; I do not believe this info is exposed in any way.Appanage
Yeah, that's what I figured. I'm surprised Apple makes it available even natively. They are overly protective of their keyboard.Zug
H
11

I believe you can access it using the stage class. Take a look at this.stage.softKeyboardRect within your view.

Note: I have not tried this personally, but you may need to access it after a softkeyboard event. Add an event listener to your text input on softKeyboardActivate, then call this.stage.softKeyboardRect to get the height and position of the keyboard.

Hydroquinone answered 14/12, 2012 at 4:49 Comment(5)
Perfect. I had never even noticed that property before. Thanks a lot.Zug
I have confirmed this works both on iOS and Android after the SoftKeyboardEvent.ACTIVATE event fires. Tested on iOS6 (iPad gen 1 and 3) as well as Android 4.2 (Galaxy Nexus) with default and SwiftKey keyboardsZug
It worked perfectly on Samsung Galaxy S3 and Galaxy Tab but the height and top dimensions are all wrong on my HTC 1 (m8). Weird!Ginoginsberg
@AntoineMouquod It seems to depend on keyboard, unfortunately. I did find an ANE (from the great guys at FreshPlanet, I believe) that was built to solve this issue, so you may want to take a look at that if you need it.Zug
@JoshJanusch thanks, it looks great! I'll try that in the next build. For now I've been using a simple hack: I'm considering the keyboard takes half of the screen and I push everything so that the selected textfield appear just on top of that. And it works. But that ane is a better solutionGinoginsberg

© 2022 - 2024 — McMap. All rights reserved.