避免EditText消耗click事件 [英] Avoid that EditText consumes click event

查看:141
本文介绍了避免EditText消耗click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常将focusablefocusableInTouch + clickable设置为false就足够了.但这在这里行不通.

Normally it's enough to set focusable, focusableInTouch + clickable to false. But here it does not work.

我希望父级LinearLayout也要消耗EditText上的点击,但它不起作用...

I want the parent LinearLayout to consume clicks on the EditText as well but it does not work...

<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会消耗点击,而不会将其移交给其父项.

I tried editable=false and inputType=none but it does not work. Why not? The EditText consumes the click and does not hand it on to it's parent.

编辑

我正在将onClickListener设置为LinearLayout,如果我直接按EditText ...

I'm setting an onClickListener to the LinearLayout and it does not work if I directly press the EditText...

推荐答案

后来,但也许其他人需要此信息. 在将focusable,focusableInTouch + clickable设置为false之后,将其添加到您的Java代码中:

Late, but maybe somebody else needs this info. After setting focusable, focusableInTouch + clickable to false, add this in your java code:

    editText.setMovementMethod(null);
    editText.setKeyListener(null);

别忘了保存这些值以便以后恢复它们:

Don't forget to save those values to restore them later:

    mMovementMethod = mEditText.getMovementMethod();
    mKeyListener = mEditText.getKeyListener();

这篇关于避免EditText消耗click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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