Simple implementation of Material 3 switches in Preferences

Niko Diamadis
May 17, 2023
That’s how it would look like (example app: FlashDim)

It has been some time now since the Material 3 design language was published by Google.

As it gains more and more popularity among Android apps it still not implemented in the Jetpack Preferences library. And unfortunately it will not be included in near future.

So here’s a quick tutorial on how to implement the Material 3 switches in your Preferences.

Implementation

1. Add this layout file to your project:

2. Add these entries to your app styling:

3. Use it.

Now you can just use the usual SwitchPreferenceCompat class in your preferences. The Android Studio preview will not display the M3 switch layout, but if you run it, it works.

Example usage:

Outro

It’s as easy as that.

I hope it works for you, please consider leaving a clap or a comment.

Thank you and have a fantastic day!

--

--