How to disable EditText in Android

前端 未结 18 1918
后悔当初
后悔当初 2020-12-13 12:03

How can I disable typing in an EditText field in Android?

相关标签:
18条回答
  • 2020-12-13 12:15

    I think its a bug in android..It can be fixed by adding this patch :)
    Check these links question 1 and question 2

    Hope it will be useful.

    0 讨论(0)
  • 2020-12-13 12:15

    Right click the text area and untick the editable option:

    enter image description here

    0 讨论(0)
  • 2020-12-13 12:17

    In code:

    editText.setEnabled(false);
    

    Or, in XML:

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

    You can try the following method :

     private void disableEditText(EditText editText) {
        editText.setFocusable(false);
        editText.setEnabled(false);
        editText.setCursorVisible(false);
        editText.setKeyListener(null);
        editText.setBackgroundColor(Color.TRANSPARENT); 
     }
    

    Enabled EditText :

    Enabled EditText

    Disabled EditText :

    Disabled EditText

    It works for me and hope it helps you.

    0 讨论(0)
  • 2020-12-13 12:18

    try this Kotlin code,

    editField.isEnabled = !editField.isEnabled

    0 讨论(0)
  • 2020-12-13 12:20

    According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines

    1. First create the object
    2. Declare EditText et1;
    3. Get by id

      et1 = (EditText) FindViewById(R.id.edittext1);
      et1.setEnabled(false);

    You can do enable or disable to every control at run time by java file and design time by XML file.

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