1

I want to display an EditText which will be edited mostly by selecting parts of it and pressing buttons to insert new values. (The values are long hex strings which I don't want the user to have to type.) Therefore, I want to suppress the display of the soft keyboard unless the user deliberately calls it up.

This question describes almost exactly the same requirement, but the accepted answer does not work on Android 5.1. When the input mode is changed to InputType.TYPE_NULL, the EditText disables all editing functionality, not just the soft keyboard. There's no cursor, no click-drag selection, etc.

Overriding onCheckIsTextEditor() as suggested in this answer behaves the same way.

Is there any way to accomplish this on Android 5?

Community
  • 1
  • 1
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82

1 Answers1

2

This was added in API 21:

EditText editText = (EditText) findViewById(R.id.edittext);
editText.setShowSoftInputOnFocus(false);

According to grepcode, this method has been present but hidden since version 4.1.1. So you can annotate the method that calls it as @TargetApi(Build.VERSION_CODES.LOLLIPOP), and protect the call itself with if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN).

Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
tachyonflux
  • 20,103
  • 7
  • 48
  • 67
  • Works great. When part of the text is selected, a drawer-like view opens from the top of the screen with "select all", "cut", and "paste" buttons. I can live with that. – Kevin Krumwiede Jun 03 '15 at 22:45
  • I edited the answer to explain the real reason it works on lower APIs. It has nothing to do with the support library. – Kevin Krumwiede Jun 24 '15 at 21:22