Android: Specify two different images for togglebutton using XML

前端 未结 1 613
粉色の甜心
粉色の甜心 2020-11-28 18:44

I\'m attempting to override the default ToggleButton appearance. Here\'s the XML that defines the ToggleButton:



        
相关标签:
1条回答
  • 2020-11-28 19:08

    Your code is fine. However, the toggle button will display the first item in your selector that it matches, so the default should come last. Arrange the items in the following manner to ensure they will all be utilized:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_checked="true" android:state_pressed="true" /> //currently pressed turning the toggle on
        <item android:state_pressed="true" /> //currently pressed turning the toggle off
        <item android:state_checked="true" /> //not pressed default checked state
        <item /> //default non-pressed non-checked
    </selector>
    
    0 讨论(0)
提交回复
热议问题