ListPreference change dialog style (radio button color)
O

2

2

ListPreferenceHey I'm using PreferenceActivity and added radio button to it using ListPreference. The problem is that listPreference uses it own dialog which has blue radio button (green on lollipop) and I need to change it to orange. I managed to get the dialog and change the headline and the divider color using the following:

listPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog dialog = (AlertDialog) listPreference.getDialog();
            if (dialog != null) {
                changeDialog(getApplicationContext(), dialog);
            }
            return true;
        }}); 



public void changeDialog(Context context, final AlertDialog dialog) {
        int titleViewId = dialog.getContext().getResources().getIdentifier("android:id/alertTitle", null, null);
        TextView title = (TextView) dialog.findViewById(titleViewId);
        title.setTextColor(context.getResources().getColor(R.color.orange));
    }

So if the title id is "android:id/alertTitle" and the divder id is "android:id/titleDivider", what is the id for the radio button?

Oyster answered 1/9, 2015 at 12:56 Comment(4)
did you figure out how to do this?Otiliaotina
Kind of.. I found a tutorial back then but it was too complicated to implement (you need to add pictures of the radio button and change the image on click or something of this sort) it isn't simple as changing the divider like I did above so I just kept its color. I can try to look it up again if you need it.Oyster
If you can add it here that will be great, for me and whoever finds this problem in the future.Otiliaotina
I couldn't find that link but I found something similar on stack overflow - #10461215 BTW - while searching for it I saw that since API 21 you can use buttonTint attribute, so it might be more simple to implement : #17120699Oyster
M
1

The right way to do this is to use <item name="colorAccent">YOUR COLOR</item> in a theme

Myrta answered 26/2, 2021 at 14:51 Comment(0)
S
1

For anyone needing it now

<!-- For Radio Button color unselected-->
<item name="colorControlNormal">@color/primary_99</item>

<!-- For Radio Button color selected-->
<item name="colorControlActivated">@color/secondary_30</item>
Sodium answered 1/2 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.