相关疑难解决方法(0)

Android:切换ToggleButton的文本颜色

要创建自定义ToggleButton,我在以下位置定义了一个新样式/res/values/styles.xml:

<style name="myToggleButton">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#000000</item>
    <item name="android:background">@drawable/my_toggle_button</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后我使用选择器指定按钮状态的外观/res/drawable/my_toggle_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true">
        <shape>
            [...]
        </shape>
    </item>
    <item android:state_checked="false"
        <shape>
            [...]
        </shape>
    </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

当状态发生变化时,如何修改此设置以切换按钮的文本颜色?

android togglebutton android-xml

19
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-xml ×1

togglebutton ×1