希望不算太晚了...
由于我们有一些辅助功能限制,我无法创建一个单独的文本视图,但我想出了这个解决方案:
我只是创建了一个自定义组件并重写了onTouchEvent
:
override fun onTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_DOWN && thumbDrawable.bounds.contains(
ev.x.toInt(),
ev.y.toInt()
)
) {
toggle()
}
return true
}
我没有找到这个问题的确切解决方案,但是你可以像这样分开TextView和Swich:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YOUR SWITCH TEXT HERE"/>
<Switch
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
并在你的代码中使用 switch setOnCheckedChangeListener。
android:clickable="true"
android:focusable="true"
android
命名空间时,支持库的每几次迭代都会导致 InflateException 异常。 - undefined