• 关于EditText的OnClickListener失效的解决办法


    最近开发,遇到一个问题,就是如果EditText只作为显示,不需要编辑文本,但需要点击该布局可以执行其他事件,就会冲突,EditText依然处于文本编辑状态;

    如:

    如:有5个EditText,最后一个只需要显示,不需要点击编辑文本,只需要点击该布局跳转到日历选择界面:

    思路如下:

    监听EditText的父布局LinearLayout,,但是EditText还是优先响应,就算设置了

    edt_birthday.setClickable(false);
    edt_birthday.setFocusable(false);

    那么也就是没响应而已;

    继续摸索:

    突然想到可以有FrameLayout:

     1 <LinearLayout
     2             android:id="@+id/ll_birthday" 
     3             android:layout_width="match_parent"
     4             android:layout_height="60dp"
     5             android:background="@color/white"
     6             android:orientation="horizontal"
     7             android:gravity="center_vertical"
     8             >
     9             <TextView 
    10                 android:layout_width="wrap_content"
    11                 android:layout_height="wrap_content"
    12                 style="@style/text_16_444444"
    13                 android:text="生日"
    14                 />
    15             <FrameLayout 
    16                 android:layout_width="match_parent"
    17                 android:layout_height="fill_parent"
    18                 >
    19                 <EditText
    20                     android:id="@+id/edt_birthday" 
    21                     android:layout_width="match_parent"
    22                     android:layout_height="wrap_content"
    23                     style="@android:style/Widget.TextView"
    24                     android:background="@null"
    25                     android:hint="请选择"
    26                     android:textColor="@color/font_444444"
    27                     android:textSize="16dp"
    28                     android:layout_marginLeft="30dp"
    29                     android:drawableRight="@drawable/icon_right"
    30                     android:editable="false"
    31                     android:maxLines="1"
    32                     android:layout_gravity="center_vertical"
    33                     />
    34                 <View 
    35                     android:id="@+id/view_birthday"
    36                     android:layout_width="match_parent"
    37                     android:layout_height="fill_parent"
    38                     android:background="@color/background_transparent"
    39                     />
    40             </FrameLayout>
    41             
    42         </LinearLayout>

    关键是EditText上面覆盖一个透明的View,那么该View就会优先获得点击响应事件。

  • 相关阅读:
    英语语法入门十五(名词所有格)
    在线调试Arduino
    CANopen和Canfestival
    嵌入式系统中的printf
    云原生爱好者周刊:Lens 5.0 发布,更炫、更快、更强!
    基于 KubeSphere 的 Nebula Graph 多云架构管理实践
    KubeSphere Meetup 北京站火热报名中 | 搭载 CIC 2021 云计算峰会
    KubeSphere Helm 应用仓库源码分析
    开启 Calico eBPF 数据平面实践
    KubeSphere 在直播应用中的实践
  • 原文地址:https://www.cnblogs.com/chq3272991/p/5417134.html
Copyright © 2020-2023  润新知