这是这种情况:
我的主题.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myTheme" parent="android:Theme.Translucent">
<item name="android:windowBackground">@color/windowBackground</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#FFFFFF</item>
<item name="android:buttonStyleToggle">@style/ToggleButton</item>
</style>
<style name="ToggleButton" parent="@android:style/Widget">
<item name="android:background">@drawable/toggle_list</item>
<item name="android:textOn">""</item>
<item name="android:textOff">""</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
</style>
</resources>
切换列表.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background" android:drawable="@android:color/transparent" />
<item android:id="@+android:id/toggle" android:drawable="@drawable/toggle_selector" />
</layer-list>
切换选择器.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false" android:drawable="@drawable/toggle_off"/>
<item android:state_checked="true" android:drawable="@drawable/toggle_on"/>
</selector>
在 onCheckedChanged 上,我插入了输出以查看它的作用。
如果我注释掉这一行,问题就在这里
<item name="android:buttonStyleToggle">@style/ToggleButton</item>
我看到标准按钮,并且我的侦听器被正确调用,
通过该行我可以正确地看到我的按钮,
但是不再调用侦听器,
并且当我按下 ToggleButton 时图像不会改变。
有人可以帮助我吗?
谢谢。