13

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?

Community
  • 1
  • 1
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
  • 1
    Try process onTextChanged or some other events instead of setEnable(false) – BNK Oct 01 '15 at 09:29
  • @BNK onTextChanged not will be applicable for this problem. onTextChanged called when user type text. – Sergey Shustikov Oct 01 '15 at 09:31
  • can i ask you how you disabled the edittext? – Sree Oct 01 '15 at 09:32
  • 1
    @Sree programmatically. Like that http://stackoverflow.com/questions/4297763/disabling-of-edittext-in-android/29433912#29433912 – Sergey Shustikov Oct 01 '15 at 09:34
  • editText.setEnabled(false); editText.setInputType(InputType.TYPE_NULL); – Sree Oct 01 '15 at 09:35
  • 1
    Perhaps this will help you ; take a look [here][1] [1]: http://stackoverflow.com/questions/22799770/allow-edittext-to-scroll-while-disabled – mariuss Oct 01 '15 at 09:35
  • I have no PC to test now. I mean you can try some events that prevent the keys entered but not prevent touch :-) – BNK Oct 01 '15 at 09:40
  • Hi! Has your issue been solved yet? And how? :) – BNK Oct 05 '15 at 21:41
  • @BNK, no one help me, so i just put `EditText` into `RelativeLayout` and put `TextView` above him. – Sergey Shustikov Oct 05 '15 at 21:43
  • I have tested my answer before posting here, have you tried? I think you can create a new project with only an editText such as `` then test my code – BNK Oct 05 '15 at 21:45
  • @ywwynm answer can be another working way, you can look at the comments between me and him :) – BNK Oct 05 '15 at 21:47

6 Answers6

14
    editText.setFocusableInTouchMode(false);
    editText.clearFocus();
Khaled Lela
  • 7,831
  • 6
  • 45
  • 73
3

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.

2

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.

Michael
  • 3,776
  • 1
  • 16
  • 27
1

editText.setKeyListener(null) should help you.

ywwynm
  • 11,573
  • 7
  • 37
  • 53
1

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>
Jin
  • 6,055
  • 2
  • 39
  • 72
0

Try to use these two attributes to your editext it will make your editext only scrollable not editable android:inputType="none" android:textIsSelectable="true" Below is the example

               <EditText
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="start"
                android:padding="20dp"
                android:layout_margin="10dp"
                android:textSize="@dimen/text_size"
                android:inputType="none"
                android:textIsSelectable="true"
                android:textStyle="normal"
                android:id="@+id/toeditext"
                android:textColor="@android:color/white"
                />
Hrusikesh
  • 185
  • 9