[英]How to make EditText Scrollable only when it is focused inside a scroll view (Kotlin)
我在 ScrollView 中有一个可滚动的 EditText,即使触摸在 EditText 上(未聚焦),我也想滚动 ScrollView,并且仅在聚焦时才使 EditText 滚动,如果需要,我可以写更多解释
I found the solution, maybe it will help someone else CODE SOLUTION:我找到了解决方案,也许它会帮助其他人代码解决方案:
@SuppressLint("ClickableViewAccessibility")
private fun addScrollToEditText() {
binding.cardYourMessageText.setOnTouchListener(OnTouchListener { v, event ->
if (binding.cardYourMessageText.hasFocus()) {
v.parent.requestDisallowInterceptTouchEvent(true)
when (event.action and MotionEvent.ACTION_MASK) {
MotionEvent.ACTION_SCROLL -> {
v.parent.requestDisallowInterceptTouchEvent(false)
return@OnTouchListener true
}
}
}
false
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.