首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >避免EditText消耗单击事件

避免EditText消耗单击事件
EN

Stack Overflow用户
提问于 2015-08-04 17:47:44
回答 2查看 2.7K关注 0票数 11

通常,只需将focusablefocusableInTouch + clickable设置为false即可。但在这里,它不起作用。

我希望父LinearLayout也可以使用对EditText的点击,但是它不能工作.

代码语言:javascript
运行
复制
<LinearLayout
    android:id="@+id/llText"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:background="?attr/selectableItemBackground"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tvText"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:paddingRight="5dp"
        android:text="@null" />

    <EditText
        android:id="@+id/etText"
        android:inputType="none"
        android:gravity="center_horizontal"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:layout_width="wrap_content"
        android:ems="4"
        android:layout_gravity="center_vertical"
        android:layout_height="wrap_content" />

</LinearLayout>

我尝试过editable=falseinputType=none,但是它不起作用。为什么不行?EditText会消耗单击,而不会将其传递给它的父级。

编辑

我正在将一个onClickListener设置为LinearLayout,如果我直接按下EditText,它就不能工作.

EN

回答 2

Stack Overflow用户

发布于 2015-10-23 13:14:05

晚了,但也许其他人需要这些信息。设置可聚焦后,focusableInTouch +可单击为false,将其添加到java代码中:

代码语言:javascript
运行
复制
editText.setMovementMethod(null);
editText.setKeyListener(null);

不要忘记保存这些值,以便稍后恢复它们:

代码语言:javascript
运行
复制
mMovementMethod = mEditText.getMovementMethod();
mKeyListener = mEditText.getKeyListener();
票数 39
EN

Stack Overflow用户

发布于 2015-08-04 17:57:37

您应该使用ViewGroup.onInterceptTouchEvent(MotionEvent)

这种方法是截取所有触摸屏运动事件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31815923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档