我在android中创建了一个切换按钮,我使用了一个选择器来改变在开启和关闭背景之间切换的背景.
我的问题是如何使背景保持在它将被点击的状态,例如,如果我按下"on",背景应该保持在"on"背景状态,但在我的情况下,一旦我停止按下按钮,它恢复到原始背景.
有谁知道如何实现它?
这是我的选择器文件:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/off" /> <!-- default -->
<item android:state_pressed="true" android:drawable="@drawable/on" /> <!-- on state -->
<item android:state_focused="false" android:drawable="@drawable/off" /> <!-- off state -->
</selector>
Run Code Online (Sandbox Code Playgroud) android ×1