oligazar
10/24/2017 - 1:08 AM

EditText with scrolling

When soft keyboard is present it's impossible to make EditText content scroll. Only with custom textListener that disallows touch event interception.



    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/etText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/spacing_normal"
        android:layout_marginLeft="@dimen/spacing_normal"
        android:layout_marginRight="@dimen/spacing_normal"
        android:layout_marginStart="@dimen/spacing_normal"
        android:layout_marginTop="@dimen/spacing_normal"
        android:ems="10"
        android:hint="@string/hint_text"
        android:inputType="text|textMultiLine"
        android:overScrollMode="always"
        android:maxLines="3"
        android:scrollbars="vertical"/>

  etText.setOnTouchListener { v, event ->
      if (v.id == R.id.etText) {
          v.parent.requestDisallowInterceptTouchEvent(true)
          when (event.action and MotionEvent.ACTION_MASK) {
              MotionEvent.ACTION_UP ->
                  v.parent.requestDisallowInterceptTouchEvent(false)
          }
      }
      false
  }