Hiding Android soft keyboard, blur event or native code?

6,571 views
Skip to first unread message

Mikko Ohtamaa

unread,
Sep 7, 2010, 8:00:04 AM9/7/10
to phonegap
Hi,

Is it possible to hide Android touch keyboard from Javascript for
<input>? On iPhone we can do this by firing blur event for the
corresponding input having the keyboard open, but this doesn't seem to
work at least with A2.1.

The problem is that we have buttons on the screen next to input. The
user presses this buttons, the application moves forward, but on
Android the keyboard stays. I assume this is some sort of
compatibility feature (some Android devices have hard keyboard).

I also found this code:

http://phonegap.pbworks.com/How-to-show-and-hide-soft-keyboard-in-Android

Could it apply for keyboards opened by WebKit (not opened manually
from Java code)?

ScottP

unread,
Sep 7, 2010, 9:23:30 AM9/7/10
to phonegap
Yes you can use that code to hide the keyboard opened by webkit. I
have that implemented in an app that I am working on. You would call
it from javascript like this: window.KeyBoard.hideKeyBoard();



On Sep 7, 8:00 am, Mikko Ohtamaa <mi...@redinnovation.com> wrote:
> Hi,
>
> Is it possible to hide Android touch keyboard from Javascript for
> <input>? On iPhone we can do this by firing blur event for the
> corresponding input having the keyboard open, but this doesn't seem to
> work at least with A2.1.
>
> The problem is that we have buttons on the screen next to input. The
> user presses this buttons, the application moves forward, but on
> Android the keyboard stays. I assume this is some sort of
> compatibility feature (some Android devices have hard keyboard).
>
> I also found this code:
>
> http://phonegap.pbworks.com/How-to-show-and-hide-soft-keyboard-in-And...

filmaj

unread,
Sep 7, 2010, 12:45:53 PM9/7/10
to phonegap
This would be a good candidate for a phonegap plug-in...

ScottP

unread,
Sep 7, 2010, 11:03:39 PM9/7/10
to phonegap

I'm not really sure how to do plug-ins for phonegap android. I just
edited the Droidgap.java file directly and recompiled. I saw there
was a bunch of stuff in the code/comments about modules but I'm kind
of a newbie. If there is a tutorial on how to do a android phonegap
plugin that'd be awesome. Cuz I had to stumble through and edit the
droidgap.java file to implement the native date picker too.

I know there are iPhone phonegap plugins but I haven't actually come
across any android ones. Perhaps I just haven't looked in the right
place.

jtoi...@gmail.com

unread,
Sep 10, 2010, 11:16:11 AM9/10/10
to phonegap
You can also have blur() hide the keyboard so you don't have to change
any of the application code by overloading the default blur prototype:

<script>
/** Replace default blur with version, which also hides the keyboard
*/
HTMLElement.prototype.defaultblur = HTMLElement.prototype.blur;
HTMLElement.prototype.blur = function(){
this.defaultblur();
window.Keyboard.hide();
};
</script>
<body>
...

Alternatively overload HTMLTextAreaElement and HTMLInputElement if you
want to be exact.

sajid saiyed

unread,
Oct 1, 2010, 11:55:09 AM10/1/10
to phon...@googlegroups.com
Does anyone know how to hide the keyboard on iPad and iPhone?

I tried:  window.KeyBoard.hideKeyBoard(); but it does not work.

Thanks
Sajid

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

ScottP

unread,
Oct 1, 2010, 1:13:28 PM10/1/10
to phonegap

You need to add the code found at link mentioned at the top of this
discussion before you can call that.
On Oct 1, 11:55 am, sajid saiyed <sajid.sai...@gmail.com> wrote:
> Does anyone know how to hide the keyboard on iPad and iPhone?
>
> I tried:  window.KeyBoard.hideKeyBoard(); but it does not work.
>
> Thanks
> Sajid
>
> > phonegap+u...@googlegroups.com<phonegap%2Bunsubscribe@googlegroups.c om>

sajid saiyed

unread,
Oct 2, 2010, 12:42:21 PM10/2/10
to phonegap
Thanks Scott,
Any idea where I need to create these classes?
In XCode there are options to add new classes but they are all Coca Touch classes.
Also anyone who has implemented this can tell me what name should I create for these classes?
Are these .m and .h files?

Regards
Sajid

ScottP

unread,
Oct 2, 2010, 6:15:58 PM10/2/10
to phonegap
My bad!! I was thinking you were asking about android. Sorry. The
above code is android only.
> > <phonegap%2Bunsubscr...@googlegroups.c om>
Reply all
Reply to author
Forward
0 new messages