Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Dear Chris,
  2.  
  3. If I understand that Article (along with your kind assistance correctly):
  4.  
  5. In my onCreateOptionsMenu() I used to have the line:
  6.  
  7. switchCompat.setThumbResource(R.drawable.ic_toggle_sound); <-- where ( ic_toggle_sound ) is the microphone icon showing ON-State.
  8.  
  9. First I would need to create an accompanying second graphic, lets call it ( ic_toggle_sound_off ) and place in the drawables.
  10.  
  11. Then I create a brand new xml selector file (let's call it ic_speaker_selector.xml)... and use that to replace the line above like:
  12.  
  13.  
  14. switchCompat.setThumbResource(ic_speaker_selector); <-- I am assuming without the .xml extension.
  15.  
  16.  
  17.  
  18. this ic_speaker_selector.xml would reside inside my ( res/drawable ) folder and since I only have two toggle sates:
  19. (ON - or checked) versus (OFF - or unchecked), then my code would probably look something like this (if I am not mistaken)
  20.  
  21.  
  22.  
  23. ----------------------------- ic_speaker_selector.xml should look like this ------------------------------------------------
  24.  
  25. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  26. <item android:state_checked="true" android:drawable="@drawable/ic_sound_on" />
  27. <item android:state_checked="false" android:drawable="@drawable/ic_sound_off" />
  28. </selector>
  29.  
  30. -----------------------------------------------------------------------------------------------------------------------------------
  31.  
  32.  
  33. Do I have it right ?
  34.  
  35. Thanks !
  36.  
  37. Alexander
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement