How to Prevent Keyboard appearing for EditText that is not enabled

前端 未结 6 756

My activity has an EditText which is supposedly not editable until user clicks on edit button for the screen.

I did edit.setEnabled(false)

相关标签:
6条回答
  • 2021-01-05 16:27

    Try setEditable(false) on your EditText.

    Set it back to true when you want someone to be able to type in it.

    0 讨论(0)
  • 2021-01-05 16:33

    in your layout file add the attribute to your EditText

    android:editable="false"

    0 讨论(0)
  • 2021-01-05 16:35

    Attention that setEditable is depecrated.

    You can use :

    setInputType(EditorInfo.TYPE_CLASS_TEXT)
    

    To turn keyboard on.

    setInputType(EditorInfo.TYPE_NULL)
    

    To turn keyboard off.

    0 讨论(0)
  • 2021-01-05 16:43

    Use edittext.setInputType(0); in your java file.

    0 讨论(0)
  • 2021-01-05 16:50

    To make EditText Write Only and not have the keyboard show up I use these two commends within the .xml layout file.

            android:editable="false"
            android:inputType="none"
    
    0 讨论(0)
  • 2021-01-05 16:51

    In API level 21, a function has been added to EditText, namely

    editText.setShowSoftInputOnFocus(boolean show);
    

    This is exactly what you need.

    0 讨论(0)
提交回复
热议问题