如何使EditText的父级可点击? [英] How to make EditText's parent clickable?
问题描述
假设我有这个粉红色的盒子:
Suppose I have this pink box:
它由LinearLayout
及其子元素组成:作为字段名的TextView
和EditText
. EditText
被有意禁用.我想要的是,用户可以在该粉红色的框中单击用户想要的任何位置.顺便说一句,请忽略您发现奇怪的所有UI/UX内容.
It consists of LinearLayout
with its children: TextView
as field name and an EditText
. EditText
is intentionally disabled. What I want is that, user can click wherever user wants on that pink box. By the way, please just ignore any UI/UX things that you found weird.
我已经尝试过,但是用户无法轻按EditText
所占据的区域.用户必须点击TextView
或粉红色框上的空白区域,以便应用程序获得点击".但是,如果用户点击EditText
的区域,则不会发生任何事情.
I've tried, but user can't tap the area that EditText
occupies. User have to tap in TextView
or blank area on pink box so that the apps got the 'click'. But if user taps on EditText
's area, nothing will happen.
我尝试使用xml属性中的某些内容,例如将LinearLayout
的clickable
设置为true
,以及所有子级或EditText
的clickable
,focusable
属性以及focusableInTouchMode
至false
都无济于事. EditText
区域仍然无法单击.
I've tried playing with some things in xml's properties, such as set LinearLayout
's clickable
to true
, and all children or just EditText
's properties of clickable
, focusable
, and focusableInTouchMode
to false
, all to no avail. EditText
area still cannot be clicked.
有什么主意吗?不能仅通过xml到达吗?是否应该以编程方式完成以绕过EditText
的点击?
Any idea? Can't it be reached just through xml? Should it be done programmatically just to turn bypass EditText
's click?
推荐答案
您可以简单地添加onTouch Listener而不是单击Listener.
You can simply add onTouch Listener instead of click Listener.
这篇关于如何使EditText的父级可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!