Sarah Khan
Sarah Khan

Reputation: 866

How to Change SwitchPreference text color when switch is enabled?

See Screenshot

I want to change that text color of 'Enabled' to blue

Here is my xml

<SwitchPreference
android:defaultValue="false"
android:key="startScan"
android:summaryOff="@string/prefs_scan_startup_summary"
android:summaryOn="Enabled"
android:title="@string/prefs_scan_startup" />

Upvotes: 2

Views: 157

Answers (1)

Merthan Erdem
Merthan Erdem

Reputation: 6058

Well... if noone else knows of a easy solution it might be tricky.

In general you could create a Sharedpreference listener that would update whatever property you want when the Switch state (and thus the SharedPreference) changes.

However I can't see a way to specifically change the textcolor of a SwitchPreference, so you might have to extend the SwitchPreference class and use your custom view where you would have access to the actual TextView to change its color.

See this for reference on extending that custom class.

Upvotes: 1

Related Questions