[android] Make EditText ReadOnly

If you just want to be able to copy text from the control but not be able to edit it you might want to use a TextView instead and set text is selectable.

code:

myTextView.setTextIsSelectable(true);
myTextView.setFocusable(true);
myTextView.setFocusableInTouchMode(true);
// myTextView.setSelectAllOnFocus(true);

xml:

<TextView
    android:textIsSelectable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"     
    ...
/>
<!--android:selectAllOnFocus="true"-->


The documentation of setTextIsSelectable says:

When you call this method to set the value of textIsSelectable, it sets the flags focusable, focusableInTouchMode, clickable, and longClickable to the same value...

However I had to explicitly set focusable and focusableInTouchMode to true to make it work with touch input.