如何使EditText的父级可点击? [英] How to make EditText's parent clickable?

查看:185
本文介绍了如何使EditText的父级可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个粉红色的盒子:

Suppose I have this pink box:

它由LinearLayout及其子元素组成:作为字段名的TextViewEditText. 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属性中的某些内容,例如将LinearLayoutclickable设置为true,以及所有子级或EditTextclickablefocusable属性以及focusableInTouchModefalse都无济于事. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆