Customise switch appearance in AndroidX preference activity

32 views Asked by At

Summary: How do I customise/style the colour and appearance of AndroidX switch preferences?

Detail: Simplifying a bit, I have an Android app that uses the AndroidX preference classes. My preference activity inherits from AppCompatActivity and creates a minimal fragment that derives from PreferenceFragmentCompat. In my preferences.xml I have a switch preference:

<SwitchPreferenceCompat
    android:key="@string/soundOnKey"
    android:title="@string/soundOnTitle"
    android:summary="@string/soundOnSummary"/>

In my styles.xml I have a style:

<style name="Theme.App.Settings" parent="Theme.AppCompat.NoActionBar">
    <item name="android:textColorPrimary">@color/colorAccent</item>
</style>

I apply this theme in my preference activity's OnCreate(). This all works as expected.

Question: How do I extend my settings style xml to specify colours for the "thumb" and "slide" parts of the switch that controls the "sound on" preference?

Thanks.

0

There are 0 answers