Hide soft keyboard on application load

前端 未结 3 414
后悔当初
后悔当初 2020-12-23 17:05

I have an application with an EditText element on the main view. This means that when my application is loaded the soft keyboard appears per default.

I

相关标签:
3条回答
  • 2020-12-23 17:16

    In your AndroidManifest.xml:

    <activity android:name="com.your.package.ActivityName"
              android:windowSoftInputMode="stateHidden"  />
    

    More details about windowSoftInputMode can be found here.

    This setting will hide soft keyboard when user enters new Activity (even if EditText control gains the focus). Soft keyboard will be shown only when user clicks the edit box control.

    0 讨论(0)
  • 2020-12-23 17:33
    InputMethodManager imm = 
        (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
    

    This will hide in all situations (even when the EditView has focus):

     EditText editView = (EditText) findViewById(R.id.editTextConvertValue);
     editView.setInputType(InputType.TYPE_NULL);
    
    0 讨论(0)
  • 2020-12-23 17:34

    You can do something easier. Add this to the LinearLayout (or any other layout that is the root):

    <LinearLayout
    ...
    android:focusable="true"
    android:focusableInTouchMode="true"
    ...
    />
    
    0 讨论(0)
提交回复
热议问题