Android ToggleButton 带有九个补丁停止工作
情况是这样的:
myTheme.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>
toggle_list.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>
toggle_selector.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>
onOnCheckedChanged 我已插入输出以查看它的作用。
这里的问题是,如果我注释掉该行,
<item name="android:buttonStyleToggle">@style/ToggleButton</item>
我会看到标准按钮并且我的侦听器被正确调用,
通过那条线,我可以正确地看到我的按钮,
但不再调用侦听器,
当我按下切换按钮时图像不会改变。
有人可以帮助我吗?
谢谢。
this is the situation:
myTheme.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>
toggle_list.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>
toggle_selector.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>
on onCheckedChanged I've inserted output to see what it does.
here the problem if i comment out the line
<item name="android:buttonStyleToggle">@style/ToggleButton</item>
I see the standard button and my listener is called correctly,
with that line I see my buttons correcly,
but the listener is no longer called,
and the image does not change when i press the ToggleButton.
Someone could help me?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论