android – 自定义复选框starStyle的外观

android – 自定义复选框starStyle的外观,第1张

概述我在ListView行的xml布局中有以下内容: <CheckBox android:id="@+id/favbutton" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" 我在ListVIEw行的xml布局中有以下内容:

<CheckBox        androID:ID="@+ID/favbutton"                androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentRight="true"        androID:layout_centerVertical="true" />

它显示了一个蓝色的星星,可以检查以选择一个喜欢的.这正是我需要的功能,但我只想自定义显示的星形图标.我想将颜色改为黄色而不是蓝色,如果可能的话也会使星形变小.是否可以通过更改应用于应用程序的主题来进行这些更改?我需要编辑什么才能更改星形图标的外观

解决方法 我解决了这个问题如下.我在res / drawable中创建了一个名为btn_star_selector.xml的文件,并按如下方式定义了选择器:

<selector xmlns:androID="http://schemas.androID.com/apk/res/androID">     <item androID:state_checked="true" androID:state_pressed="true"  androID:drawable="@drawable/btn_star_on_pressed" />     <item androID:state_checked="false" androID:state_pressed="true"      androID:drawable="@drawable/btn_star_off_pressed" />     <item androID:state_checked="true" androID:drawable="@drawable/btn_star_on" />     <item androID:state_checked="false" androID:drawable="@drawable/btn_star_off" /></selector>

定义了这个选择器后,我在复选框定义中替换了这一行

  

有了这个

androID:button="@drawable/btn_star_selector"

然后我创建了四个图像来表示复选框的不同状态,即打开,关闭,按下和关闭按钮,并将它们放在res / drawables中.

希望这有助于其他任何试图找出如何自定义复选框的人.

总结

以上是内存溢出为你收集整理的android – 自定义复选框starStyle的外观全部内容,希望文章能够帮你解决android – 自定义复选框starStyle的外观所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1129871.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存