Skip to content

Instantly share code, notes, and snippets.

@redleafar
Last active September 15, 2016 18:54
Show Gist options
  • Save redleafar/024b03060ceea7040e69a4d58cb329c5 to your computer and use it in GitHub Desktop.
Save redleafar/024b03060ceea7040e69a4d58cb329c5 to your computer and use it in GitHub Desktop.
EditText as TextArea

In the layout:

<EditText
    android:id="@+id/textArea_information"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:gravity="top|left"
    android:inputType="textMultiLine"
    android:overScrollMode="always"
    android:scrollbarStyle="insideInset"
    android:scrollbars="vertical"
    android:lines="6"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:scrollHorizontally="false" />

In the Activity/Fragment:

EditText textArea = (EditText) findViewById(R.id.textArea_information);

textArea.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.getParent().requestDisallowInterceptTouchEvent(true);
                switch (event.getAction() & MotionEvent.ACTION_MASK){
                    case MotionEvent.ACTION_UP:
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                        break;
                }
                return false;
            }
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment