Android: toggle text color of ToggleButton

谁都会走 提交于 2019-12-03 05:50:38
Devunwired

Create a similar state list for the text colors you would like, and place it in res/color, e.g.

res/color/toggle_color.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="#070" />
    <!-- Default State -->
    <item android:color="#A00" />
</selector>

Then set this resource as the text color of the button:

<item name="android:textColor">@color/toggle_color</item>

P.S., it's good practice to have the last item in a selector not have any state flags attached (i.e. a default state) rather than defining it with the inverse of the above states.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!