Changing android preference icon with SwitchPreference Setting

Viewed 1276

I have a SwitchPreference in my android app which can be set to "on" or "off". I have an icon for this SwitchPreference. XML code below

<SwitchPreference
    android:title="@string/psm_pinterest"
    android:defaultValue="false"
    android:key="@string/pref_social_pinterest"
    android:icon="@drawable/pinterest_bw"
    android:summaryOn="@string/psm_pinterest_summary_on"
    android:summaryOff="@string/psm_pinterest_summary_off"/>

However, I also want the icon to change as and when the SwitchPreference is changed. Is there anyway to do it via XML? I tried to create a "drawable" xml using the "state" settings but none of the "states" are getting called when I change the SwitchPreference setting.

I am now handling this programatically but I am looking at a more efficient way to do it via XML itself. Appreciate the help

2 Answers
Related