How to set editable true/false EditText in Android programmatically?

前端 未结 12 1185
予麋鹿
予麋鹿 2020-12-09 02:04

We can set editable property of EditText in XML layout but not programatically, but there is no setEditable() method!

If EditText

相关标签:
12条回答
  • 2020-12-09 02:42

    An easy and safe method:

    editText.clearFocus();
    editText.setFocusable(false);
    
    0 讨论(0)
  • 2020-12-09 02:46

    try this,

    EditText editText=(EditText)findViewById(R.id.editText1);
    
    editText.setKeyListener(null);
    

    It works fine...

    0 讨论(0)
  • 2020-12-09 02:46

    hope this one helps you out:

    edittext1.setKeyListener(null);
    edittext1.setCursorVisible(false);
    edittext1.setPressed(false);
    edittext1.setFocusable(false);
    
    0 讨论(0)
  • 2020-12-09 02:46

    Try this it is working fine for me..

    EditText.setInputType(0);
    EditText.setFilters(new InputFilter[] {new InputFilter()
    {
    @Override
    public CharSequence filter(CharSequence source, int start,
                                int end, Spanned dest, int dstart, int dend) 
    {
    return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
    
    }
    }
    });
    
    0 讨论(0)
  • 2020-12-09 02:48
    editText.setFocusable(false);
    editText.setClickable(false);
    
    0 讨论(0)
  • 2020-12-09 02:52

    Fetch the KeyListener value of EditText by editText.getKeyListener() and store in the KeyListener type variable, which will contain the Editable property value:

    KeyListener variable;
    variable = editText.getKeyListener(); 
    

    Set the Editable property of EditText to false as:

     edittext.setKeyListener(null);
    

    Now set Editable property of EditText to true as:

    editText.setKeyListener(variable);  
    

    Note: In XML the default Editable property of EditText should be true.

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