How to stop the android soft keyboard from ever coming up in my entire application
Asked Answered
W

5

3

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.

Winston answered 12/3, 2010 at 0:6 Comment(2)
The way I got around this for my demo was to turn the Android keyboard off for the entire phone: "Settings -> Language & keyboard -> Android Keyboard (uncheck)". Since the phone comes with a hard keyboard that is always visible, this seems appropriate anyway. Thanks to both CommonsWare and Macarse who gave good directions for anyone else who runs into this problem to explore.Winston
One more thing, if you find yourself in the same situation, please follow the link in CommonsWare's comments to Android bug 7115 and click the star to vote it up.Winston
U
5

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.

Umbilication answered 12/3, 2010 at 0:43 Comment(3)
Thanks, but that doesn't help me do a demo tomorrow. Any other ideas?Winston
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 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.Umbilication
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.Winston
G
2

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.

Glossitis answered 12/3, 2010 at 1:54 Comment(0)
C
2

If an EditText has an inputType of 0, the soft keyboard will never pop up when that EditText is selected.

EditText editText = findViewById(R.id.edit_text);
editText.setInputType(0);

This will of course need to be done for all the EditTexts in your application, or you could always subclass EditText and set the input type to 0 in your constructor.

Setting the xml inputType parameter will not do, since that corresponds to a call to the setRawInputType method, which does not remove the KeyListener.

Campobello answered 18/1, 2011 at 9:8 Comment(0)
R
2

I solved it by overriding onCheckIsTextEditor method in my a-bit-custom EditText.

@Override
public boolean onCheckIsTextEditor() {
    return false;
}
Resistor answered 16/3, 2011 at 7:48 Comment(0)
Q
0

Where ever you have Edit text, put this code..

edittext.setInputType(InputType.TYPE_NULL);      
if (android.os.Build.VERSION.SDK_INT >= 11)   
{  
    edittext.setRawInputType(InputType.TYPE_CLASS_TEXT);  
    edittext.setTextIsSelectable(true);  
}
Quaker answered 10/5, 2013 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.