Hiding the android keyboard for EditText

前端 未结 10 2030
慢半拍i
慢半拍i 2020-12-17 14:27

Whenever I click in the EditText the Android keyboard popup window appears, but I don\'t want the keyboard to pop up.

I want to permanently hide the and

相关标签:
10条回答
  • 2020-12-17 15:03

    In your xml set attribute editable to false. it won't let you edit the text and the keyboard will not be opened.

    <EditText
         android:editable="false"
     />
    
    0 讨论(0)
  • Try This

     public void disableSoftKeyboard(final EditText v) {
                if (Build.VERSION.SDK_INT >= 11) {
                    v.setRawInputType(InputType.TYPE_CLASS_TEXT);
                    v.setTextIsSelectable(true);
                } else {
                    v.setRawInputType(InputType.TYPE_NULL);
                    v.setFocusable(true);
                }
            }
    
    0 讨论(0)
  • 2020-12-17 15:07

    Solution can be found here :

    public void onCreate(Bundle savedInstanceState) {
    
    edittext = (EditText) findViewById(R.id.EditText01);
    
    edittext.setOnEditorActionListener(new OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
             if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
             }
             return false;
          }
       });
    }
    
    0 讨论(0)
  • 2020-12-17 15:08

    Setting the flag textIsSelectable to true disables the soft keyboard.

    You can set it in your xml layout like this:

    <EditText
        android:id="@+id/editText"
        ...
        android:textIsSelectable="true"/>
    

    Or programmatically, like this:

    EditText editText = (EditText) findViewById(R.id.editText);
    editText.setTextIsSelectable(true);
    

    The cursor will still be present, you'll be able to select/copy/cut/paste but the soft keyboard will never show.

    0 讨论(0)
  • 2020-12-17 15:08

    In your xml file you can use this:

    android:editable="false"
    
    0 讨论(0)
  • 2020-12-17 15:16

    In the manifest:

      <activity
            android:name=".YourActivity"
           .
           .
           .
            android:windowSoftInputMode="stateAlwaysHidden" >
       </activity>
    
    0 讨论(0)
提交回复
热议问题