Android switch:如何禁用对触摸事件的响应?
Android switch: how to disable response to touch event?
所以我正在开发一个 Android 应用程序,我添加了一些开关来指示某些元素的状态。
但问题是我希望通过线程控制状态,而不是用户触摸屏幕。
是否可以关闭它?或者如果不是,我可以用什么来表示类似的状态改变?
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"/>
这是我添加的开关。不管由谁来操作,我只希望禁用用户的触摸事件。
我尝试了一些解决方案并找到了一个有效的解决方案。
对于每个开关,添加
android:clickable="false"
会按照我的要求去做。
所以我正在开发一个 Android 应用程序,我添加了一些开关来指示某些元素的状态。
但问题是我希望通过线程控制状态,而不是用户触摸屏幕。
是否可以关闭它?或者如果不是,我可以用什么来表示类似的状态改变?
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"/>
这是我添加的开关。不管由谁来操作,我只希望禁用用户的触摸事件。
我尝试了一些解决方案并找到了一个有效的解决方案。
对于每个开关,添加
android:clickable="false"
会按照我的要求去做。