Android EditText Vertical Scrolling Problem

后端 未结 5 1711
猫巷女王i
猫巷女王i 2020-12-06 03:20

I\'m using an EditText of some predefined size, however when a user enters more text then fits in the text box, they aren\'t able to scroll the text with touch. Scrolling do

5条回答
  •  北海茫月
    2020-12-06 03:48

    A simple way to do scroll-able text in edittext if parent is NestedScrollView or ScrollView

    XML code

    android:gravity="top"
    android:inputType="text|textMultiLine"
    android:lines="5"
    

    Use below code for Kotlin

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

提交回复
热议问题