How to make EditText not editable through XML in Android?

后端 未结 27 1917
梦谈多话
梦谈多话 2020-11-28 17:35

Can anyone tell me how to make an EditText not editable via XML? I tried setting android:editable to false, but

  1. it is de
27条回答
  •  猫巷女王i
    2020-11-28 18:30

    In addition to @mahe madi you can try this as well

    editText.setEnabled(false);
    editor.setTextColor(Color.BLACK);
    

    This method will hide cursor, lose focus and more importantly set text color to black behaving like TextView.

    And to revert Back to editText simply do this to gain all the properties of EditText.

    editText.setEnabled(true);
    

    Hope it Helps :)

提交回复
热议问题