切换拇指可以在选择器中的state_enabled设置
我正在用自己的拇指和轨道进行自定义开关。我想要的是,在我的拇指XML中,在检查状态下设置了不同的颜色,并且在禁用开关时,还设置了不同的颜色。问题在于,当我将state_enabled设置为false,Nothind发生时,只有检查状态起作用时,为什么会发生这种情况?
<?xml version="1.0" encoding ="utf-8"?>
<selector xmlns:android.....>
<item android:state_checked = "true">
<shape android:shape = "oval">
<size android:width = "24dp" android:height="24dp"/>
<solid android:color="@color/green"/>
</shape>
</item>
<item android:state_checked="false">
<shape android:shape="oval">
<size android:width = "24dp" android:height="24dp"/>
<solid android:color="@color/red"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="oval">
<size android:width = "24dp" android:height="24dp"/>
<solid android:color="@color/black"/>
</shape>
</item>
</selector>
I'm making a custom switch with my own thumb and track. What I want is, in my thumb xml, set a different color in checked state, unchecked state and also, set a different color when the switch is disabled. The problem is that when I set state_enabled to false, nothind happen, just checked states works, why is this happening?
<?xml version="1.0" encoding ="utf-8"?>
<selector xmlns:android.....>
<item android:state_checked = "true">
<shape android:shape = "oval">
<size android:width = "24dp" android:height="24dp"/>
<solid android:color="@color/green"/>
</shape>
</item>
<item android:state_checked="false">
<shape android:shape="oval">
<size android:width = "24dp" android:height="24dp"/>
<solid android:color="@color/red"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="oval">
<size android:width = "24dp" android:height="24dp"/>
<solid android:color="@color/black"/>
</shape>
</item>
</selector>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下。此链接中有类似的解决方案。
https://stackoverflow.com/a/a/1238390/6183169
Try this. There is similar solution in this link.
https://stackoverflow.com/a/12383390/6183169