Android: Specify two different images for togglebutton using XML

Android: Specify two different images for togglebutton using XML

Asked on December 28, 2018 in XML.
Add Comment


  • 1 Answer(s)

    Specify two different images for togglebutton using XML:

         Although, the toggle button will show the starting item in the selector that it matches, so atlast the default should be there. Sequence the item to confirm that they will all be utilized by the following manner,

    <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>
    
    Answered on December 28, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.