0

Given EditText et;

When I programatically call et.setText("Hello World") a soft keyboard appears on the screen.

I want to prevent this soft keyboard from showing up. I don't mind if et remains focused or not.

I have tried et.clearFocus();

I still want to be able to focus on et and show the keyboard when tapping on it. Just not from et.setText()

Greg Peckory
  • 6,660
  • 15
  • 61
  • 101

3 Answers3

2

You can use this code programmatically. But if you just want to display text use TextView

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Rainmaker
  • 7,673
  • 4
  • 38
  • 63
1

Add this to the manifest.xml to your <activity/> tag:-

android:windowSoftInputMode="stateHidden"

like:-

<activity android:name=".YourActivity"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden"></activity>

setText() wont show up the keyboard

Santanu Sur
  • 8,836
  • 7
  • 24
  • 43
1

You can prevent keyboard to display do like this

        et.setText("Hello World")
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
SahdevRajput74
  • 742
  • 6
  • 18