Make EditText ReadOnly

前端 未结 22 1277

I want to make a read-only EditText view. The XML to do this code seems to be android:editable=\"false\", but I want to do this in code.

H

22条回答
  •  旧巷少年郎
    2020-12-04 19:16

    Use this code:

    editText.setEnabled(false);
    editText.setTextColor(ContextCompat.getColor(context, R.color.black);
    

    Disabling editText gives a read-only look and behavior but also changes the text-color to gray so setting its text color is needed.

提交回复
热议问题