Loading

关于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就会优先获得点击响应事件。

posted @ 2016-04-21 15:28  集君  阅读(5793)  评论(0编辑  收藏  举报