soft keyboard height / is active

1,589 views
Skip to first unread message

Chris

unread,
Sep 13, 2015, 6:34:55 AM9/13/15
to AndroidScript
I have a webview set to 1.0, 1.0 and have some textareas.

When the keyboard opens I need to know how much space it is using, or the height left....

function alertSH() {
var height = app.GetScreenHeight();
var layHeight = lay.GetHeight();
app.Alert(height + ', ' + layHeight);
}

Neither of these change when the keyboard is open.

How can we get this height change?

Hoe can we know if the soft keyboard is covering layouts?

Message has been deleted

Steve Garman

unread,
Sep 13, 2015, 8:26:27 AM9/13/15
to AndroidScript
Yes, this can be very irritating.

Sometimes, depending on your layout, it can be a help to put the lower controls on a Scroller and to scroll them up either manually or programmatically.

Chris

unread,
Sep 13, 2015, 12:53:18 PM9/13/15
to AndroidScript
A app.isSoftKeyboardActive() returning a bool would allow us to manipulate heights of the layouts.

This is available, just needs added to DroidScript. (It's possible in Java)

@Dave Smart.... can we get this feature? It is needed for serious app development.

Chris

unread,
Sep 13, 2015, 1:21:15 PM9/13/15
to AndroidScript
Looks harder than I thought. Found this solution referenced multiple times online.

http://www.ninthavenue.com.au/how-to-check-if-the-software-keyboard-is-shown-in-android

@Dave - what you think?

Chris

unread,
Sep 13, 2015, 1:28:46 PM9/13/15
to AndroidScript
Concerning the above 'hack' -

Put the IMMResult private class in your Activity (or in a separate file if you need to reuse it).

Put the first code block wherever you need conditional logic based on the state of the keyboard. This code block first shows the keyboard then checks the IMMResult to find out if it was hidden beforehand or not.

You could change it to first hide the keyboard then query the result if that works better for you.

It's quite a mess really, but it should give you the information you need.


This would work??

Peter de Rooij

unread,
Sep 13, 2015, 1:59:02 PM9/13/15
to AndroidScript
This basically opens (or hides) the keyboard and waits for the result. That is different from detecting if the keyboard is showing.

Why do you want to know if the keyboard is active and its height and why do you think it is needed for 'serious app development'?

Peter de Rooij

unread,
Sep 13, 2015, 2:29:05 PM9/13/15
to AndroidScript
Ps: I ask this because it usually is of no concern for a developer to handle keyboard showing or hiding. Android resizes the controls when the keyboard is shown or hidden. You can influence this a bit by using android:windowSoftInputMode="adjustResize" which causes your complete layout to remain visible when the keyboard is shown.

Chris

unread,
Sep 13, 2015, 7:29:59 PM9/13/15
to AndroidScript
Actually, the code just uses an open or close of the keyboard to get its current state. Thereafter updating so we can check if it is open.

Serious development WITH droidscript. Since a lot of actions take place within a webview, the keyboard will cover content. If we could do
web.isKeyboardActice or something, we can adjust the height of the webview.

Example. Create a webview with 1, 1 as dimensions.
In the html have a full page textarea. When you start typing (after so many lines) it will go UNDER the keyboard.

Since DroidScript is a hybrid, and using html is a BIG part of it, this is neccessary!

Hope I explained well.

Sean Loper

unread,
Sep 14, 2015, 2:51:46 AM9/14/15
to AndroidScript

Chris

unread,
Sep 14, 2015, 3:30:31 AM9/14/15
to AndroidScript
The viewport is useless in this situation, it doesn't change becauase the webview is under it. That is a reference to mobile site and a browser.

Still hoping for a isKeyboardActive() hack....

:)

Dave Smart

unread,
Sep 16, 2015, 8:03:41 AM9/16/15
to AndroidScript
OK Guys,

I've added some new methods which should help you with these problems:-
(I've tested on EditText and a TextArea inside a WebView)

app.ShowKeyboard( ctrl );
ctrl.SetFocus();
app.IsKeyboardShown();

I had to remove the IME_FLAG_NO_EXTRACT_UI mode from the EditText control because the IsKeyboardShown method does not work properly when that mode is enabled (its the mode where the keyboard fills the whole screen in landscape orientation).  You can force this mode back on if you use the 'Extract' option though)

Note: ShowKeyboard will not work unless the given control currently has the focus.

Regards
David


Chris

unread,
Sep 16, 2015, 4:48:43 PM9/16/15
to AndroidScript
About to dig in Dave, one question. I'm not sure I have it so I'm asking.

Please explain 'ctrl' - what is needed here?

Also, how do I update DroidScript?

Chris

unread,
Sep 16, 2015, 4:53:23 PM9/16/15
to AndroidScript
I've been up 30+ hours. :)

ctrl would be the webview?

Nick Whiteley

unread,
Sep 18, 2015, 5:12:20 AM9/18/15
to AndroidScript
Hi Dave,

I have similar problem with keyboard hiding the text box in webview.
Are the new methods in the latest build or do we need to wait for update?
any chance you could provide a code sample for this?

Nick.

Dave Smart

unread,
Sep 25, 2015, 5:36:33 AM9/25/15
to AndroidScript
Hi Nick,

I sent an alpha version and code sample to Chris.. did i send you one?  I can send you one if you like but the functionality is coming in the next private beta.

Reply all
Reply to author
Forward
0 new messages