2

Is there a way to block the soft keyboard when an input get foucs, but DO NOT lose the input's focus (keep the cursor in the input filed)?

I'm programming a phonegap application on android. I have to show a custom keyboard, which is not an IME, just is an android activity, paint as a soft keyboard(for some reason, I can change this solution). The problem is that when the input get focus, the custom keyboard and system's soft keyboard(IME) both are displayed. Can I block the system's soft keyboard ?

Hum, it's a phonegap application and the input is a HTML input and sorry for my poor English.

Ethan Zheng
  • 21
  • 1
  • 3

2 Answers2

1

Had a similar situation myself on a current cordova/backbone app we're working on.

Our situation:

We had datepicker / timepicker plugins we were using with JQuery. These plugins provided their own interface for selecting and inputting time/date values. However whenever an input field for a date or time picker gained focus the soft-keyboard would be revealed. This was confusing, as the user is expected to input data via the onscreen calendar/time dial and not the softkeyboard.

Solution

Our solution for this was to add the readonly attribute to our <input>'s. Since we were setting these values programmatically, there was no reason to make these inputs read/write fields. From our experience it seems that setting a field to readonly will prevent the soft keyboard from showing up when those input fields receive focus

BardiaD
  • 99
  • 1
  • 8
0

In config.xml add the following preferences:

  <preference name="android-windowSoftInputMode" value="stateHidden"/>

other examples here:

http://developer.android.com/guide/topics/manifest/activity-element.html

android:windowSoftInputMode=["stateUnspecified",
                             "stateUnchanged", "stateHidden",
                             "stateAlwaysHidden", "stateVisible",
                             "stateAlwaysVisible", "adjustUnspecified",
                             "adjustResize", "adjustPan"] >

In answer to op's comment:

See this: How can I hide the Android keyboard using JavaScript?

Community
  • 1
  • 1
BenAtack
  • 98
  • 7
  • It doesn't work on my problem. I mean that how to block soft keyboard when the input get focus. The android:windowSoftInputMode is for 'The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention'. – Ethan Zheng Jul 24 '14 at 02:19
  • Forgive me, but that sounds like exactly what you are after... maybe you can explain the issue in more depth? – BenAtack Jul 24 '14 at 12:13
  • I try to describe it more clear: When a HTML input element gets a focus(whatever touch on the input or call input.focus()), then a soft keyboard will be bring out. This is the OS's default behavior, right? And I attempt to prevent this default behavior. I hope this soft keyboard is hidden, and the input still get the focus(the cursor is still in the input field). How can I do it? The attribute of 'android:windowSoftInputMode' is not work. It seems to set the soft-keyboard's state at the moment of the application is opened but user touches the input. – Ethan Zheng Jul 25 '14 at 05:41
  • Hey I have the same problem I need to Prevent the Keyboard from showing on focus / click in the field it should only show when I call show() or hide() from the ionic keyboard plugin – stackg91 May 23 '16 at 07:19