views:

642

answers:

2

I'm developing an application on a hardware device that has a built-in hardware keyboard that does not slide out so is always visible (like a blackberry). Therefore, I NEVER want the soft keyboard to display for my entire application. I'm aware of another SO question that gives the following lines of code:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

But I don't know where to put this code to hide the soft keyboard in all places where it might possibly appear in my Activity. I have tried adding the code to Activity.onUserInteraction to no avail. It seems the keyboard appears after the onUserInteraction executes.

I also tried adding the following to my <Activity>:

<activity 
    android:windowSoftInputMode="stateAlwaysHidden"
>

Soft keyboard still appears.

+3  A: 

Your application should not do anything. The device's firmware should contain a configuration that inhibits the soft keyboard based on the hardware keyboard being visible, just like every other Android device that has a hardware keyboard. If that is not happening, talk to the hardware maker and see if they are planning on addressing this.

CommonsWare
Thanks, but that doesn't help me do a demo tomorrow. Any other ideas?
JohnnyLambada
Well, `android:windowSoftInputMode="stateAlwaysHidden"` should have done it, based on my reading of the docs. I can confirm that it doesn't work, at least on Android 2.0.1 and 2.1. I suspect there's a bug -- I have filed an issue at http://code.google.com/p/android/issues/detail?id=7115. That, of course, doesn't help you for tomorrow. :-( The only way to detect that the soft keyboard has appeared is to detect the fact that your content view has resized. So, extend whatever your layout's root `ViewGroup` is, override `onSizeChanged()`, and try `hideSoftInputFromWindow()` at that point.
CommonsWare
Thanks for filing the bug report. I went ahead and voted for it. I also appreciate your answer -- I ended up taking the vendor's approach as explained my comment to the question.
JohnnyLambada
+2  A: 

An easy workaround for tomorrow presentation:

I would create a new IME with an empty view. Here are two openSource projects for you to look at some code.

If you want to know more about input methods, go to Creating an input method.

Macarse