2

I have an EditText and I'd like my app to NEVER show the soft keyboard when I focus on it. I'm using an external keyboard.

I'd like to do this in my activity's onCreate:

EditText debugPrompt = (EditText)findViewById(R.id.debug_prompt);
debugPrompt.setShowSoftInputOnFocus(false);

Problem is, I'm using SDK 19, and setShowSoftInputOnFocus was added in 21. Is there any equivalent?

My best try so far is:

getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
EditText debugPrompt = (EditText)findViewById(R.id.debug_prompt);
debugPrompt.requestFocus();

This does part of the job. The keyboard is hidden after line 4, but shows itself when I tap inside the EditText.

dinosaur
  • 3,164
  • 4
  • 28
  • 40
  • I solved this by upgrading my SDK. An answer would probably still be useful for any developers who can't upgrade. – dinosaur Apr 27 '16 at 02:09

1 Answers1

0
public static void disableinputRetaincursor(EditText editText) {
    if (Build.VERSION.SDK_INT >= 11) {
        editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
        editText.setTextIsSelectable(true);
    } else {
        editText.setRawInputType(InputType.TYPE_NULL);
        editText.setFocusable(true);
    }
}
atish naik
  • 226
  • 2
  • 11