Android Question Changing colorAccent, colorPrimary, etc at runtime

trueboss323

Active Member
Licensed User
Longtime User
Hi all,
In my app I give the user the option to change the theme, when the user selects a theme then I would like to programmatically change all the accent,primary, text and dialog colors in the app. How can I achieve this?
 

trueboss323

Active Member
Licensed User
Longtime User
Hi Erel,
I used the code that you mentioned in the thread. But when using with AppCompact it does not display correctly, see attached screenshot. I tried changing to white material theme as an example. As a result, it adds a second action bar, and it turns the checkboxes black and buttons white making it harder to see.
 

Attachments

  • theme.png
    theme.png
    35.1 KB · Views: 851
Upvote 0

trueboss323

Active Member
Licensed User
Longtime User
Yes, I've uploaded a small project that demonstrates this problem. On the dropdown menu, simply select 'Light' and you will see it reproduce.
 

Attachments

  • SettingsExample.zip
    16.2 KB · Views: 497
Upvote 0

corwin42

Expert
Licensed User
Longtime User
You set the Theme to Theme.Material.Light which is not an Appcompat theme.

AppCompat can only work with an Appcompat theme.
 
Upvote 0
Top