Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText disable edit but allow scrolling

I know that is possible to disable editing EditText.

Answers is here, and here.

But, when i disable EditText it also disabled vertical scroll in this text.

Is it possible to disable only editing, but allow scrolling?

like image 924
Sergey Shustikov Avatar asked Oct 01 '15 09:10

Sergey Shustikov


4 Answers

    editText.setFocusableInTouchMode(false);
    editText.clearFocus();
like image 157
Khaled Lela Avatar answered Nov 14 '22 14:11

Khaled Lela


Use this porperties in your EdittText:

android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"

Your EditText will be enable, but not focusable for edit. Then, you will able to scroll (in vertical on this case) and will not able to edit.

like image 43
Jean Gonçalves Avatar answered Nov 14 '22 12:11

Jean Gonçalves


I've found that just disabling the key listener, focusable and cursor seems to work:

editText.setKeyListener( null );
editText.setFocusable( false );
editText.setCursorVisible(false);

As long as you keep the edit text enabled you seem to be able to scroll the text still.

like image 2
Michael Avatar answered Nov 14 '22 14:11

Michael


If you wrap your EditText in a ScrollView then you should be able to preserve the scroll behavior.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText ... />

</ScrollView>
like image 1
Jin Avatar answered Nov 14 '22 14:11

Jin