Android开关:如何禁用对触摸事件的响应?

时间:2015-02-20 15:08:43

标签: android user-interface

所以我正在开发一个Android应用程序,并且我添加了一些开关来指示某些元素的状态。

但问题是我希望通过线程控制状态,用户触摸屏幕上的instread。

是否可以将其关闭?或者如果没有,我可以用什么来表示类似的状态变化?

fragment.xml

<TableRow
        android:id="@+id/card6"     
        android:layout_width="match_parent"     
        android:layout_height="wrap_content"    
        android:padding="5dp"> 

            <TextView     
                android:layout_height="wrap_content"    
                android:layout_width="wrap_content"    
                android:text="@string/card6"/>    

            <Switch      
                android:id="@+id/card6_switch"        
                android:layout_width="wrap_content"      
                android:layout_height="wrap_content"/>      

这是我添加的开关。无论操纵它的线程如何,我只希望禁用用户的触摸事件。

1 个答案:

答案 0 :(得分:3)

我已经尝试了一些解决方案并找到了一个有效的方法。

对于每个开关,添加

android:clickable="false"    

会按照我的要求行事。