0

I know this question has been asked alot, but I tried several solutions suggested and none has worked as expected.

I have an EditText that opens the keyboard when I launch that activity, how can prevent it from launching the keyboard.

//Solutions I have tried thus far
//Solution 1
//XML
android:editable ="false" <!--is deprecated & does not work-->

//Solution 2
//XML
android:focusable="false" <!--Can no longer use the EditText -->

//Solution 3
//JAVA
editText.setinputType(InputType.TYPE_NULL); // Works but I can no longer use the edit text to add input

//Solution 4 - Similar to Solution 2
editText.setInputType(0); // Works but I can no longer use the edit text to add input

//Solution 5
//Using InputMethodManager
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(),0); //Does not work
Oush
  • 2,046
  • 16
  • 17

4 Answers4

1

Try this Use android:windowSoftInputMode="stateHidden" inside manifest file to your activity like below code

"stateHidden"

The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.

SAPME CODE

    <activity android:name=".MainActivity"
        android:windowSoftInputMode="stateHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
AskNilesh
  • 58,437
  • 15
  • 99
  • 129
1
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

this worked for me

Silva
  • 172
  • 9
1

add this line in on create

 // Hide the keyboard.
    getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
    );
vinay
  • 149
  • 7
1

Please try this on your manifest :

<activity
        android:name="com.snapit.up.LoginActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan|stateHidden" />

it helps you.

Android Geek
  • 7,328
  • 2
  • 17
  • 32