简体   繁体   中英

Change ListPreference's colors to match theme style

I'm using a ListPreference in my settings and I want the colors to adapt to the ones of the current theme. Currently I am changing the theme's alertDialogTheme style to my own. I have figured out how to change the dialog title's color, dialog button's colors, the radio button's text and the radio button's color of the currently selected item. I want to change the color of the unselected items' radio button. I circled in red the colors that I want to change.

ListPreference:

黑暗主题 灯光主题

Theme style:

<style name="Theme" parent="Theme.MaterialComponents.DayNight">
    <item name="alertDialogTheme">@style/NoteCreation.Dialog</item>
</style>

<style name="NoteCreation.Dialog" parent="Theme.MaterialComponents.Dialog.MinWidth">
    <item name="colorAccent">@color/colorPrimaryDark</item>
    <item name="textColorAlertDialogListItem">@color/onSurface</item>
    <item name="android:textColor">@color/onSurface</item>
    <item name="android:background">@color/surface</item>
    <item name="buttonBarNegativeButtonStyle">@style/NoteCreation.Dialog.Button</item>
    <item name="buttonBarPositiveButtonStyle">@style/NoteCreation.Dialog.Button</item>
</style>

<style name="NoteCreation.Dialog.Button" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
    <item name="android:textColor">@color/colorPrimary</item>
</style>

Changing the android:textColorSecondary attribute of the NoteCreation.Dialog did it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM