Override the default PreferenceScreen divider with an MD3 one

This commit is contained in:
lynxnb 2023-03-07 13:56:51 +01:00 committed by Niccolò Betto
parent b12a2bdc3e
commit 6fcb09bd2d
3 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?><!-- Material Divider for PreferenceScreen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="?attr/colorOutlineVariant" />
<size
android:width="1dp"
android:height="1dp" />
</shape>
</item>
</layer-list>

View File

@ -16,4 +16,9 @@
<style name="App.Preference.SwitchPreferenceCompat.Material3" parent="Preference.SwitchPreferenceCompat.Material"> <style name="App.Preference.SwitchPreferenceCompat.Material3" parent="Preference.SwitchPreferenceCompat.Material">
<item name="android:widgetLayout">@layout/preference_widget_material_switch</item> <item name="android:widgetLayout">@layout/preference_widget_material_switch</item>
</style> </style>
<!-- Override the default divider used in PreferenceScreen -->
<style name="App.PreferenceFragment.Material" parent="PreferenceFragment.Material">
<item name="android:divider">@drawable/preference_list_divider_m3</item>
</style>
</resources> </resources>

View File

@ -39,6 +39,8 @@
<item name="alertDialogTheme">@style/ThemeOverlay.App.MaterialAlertDialog</item> <item name="alertDialogTheme">@style/ThemeOverlay.App.MaterialAlertDialog</item>
<!-- Workaround for AndroidX PreferenceScreen since it uses colorAccent as categories text color --> <!-- Workaround for AndroidX PreferenceScreen since it uses colorAccent as categories text color -->
<item name="colorAccent">?attr/colorPrimary</item> <item name="colorAccent">?attr/colorPrimary</item>
<!-- Override the default divider used in PreferenceScreen -->
<item name="preferenceFragmentCompatStyle">@style/App.PreferenceFragment.Material</item>
<!-- Override the default switch preference style to use the MD3 switch --> <!-- Override the default switch preference style to use the MD3 switch -->
<item name="switchPreferenceCompatStyle">@style/App.Preference.SwitchPreferenceCompat.Material3</item> <item name="switchPreferenceCompatStyle">@style/App.Preference.SwitchPreferenceCompat.Material3</item>
</style> </style>