I have:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorAccent">@color/myColor</item>
</style>
But I want to allow the user to change the accent color. Can I do it with AppCompat?
No you can't, because the accent color is defined in the theme and themes are read-only in Android.
The only thing you can do is switch themes or set the color of each component manually.
Note: you can apply a theme to a portion of UI instead of the whole Activity in order to change the accent color (or other things) locally. To do so, you can use the android:theme
attribute in your XML layout with the AppCompat library, or you can inflate a layout by providing a ContextThemeWrapper
as context to your LayoutInflater
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With