3

I'd like to dynamically change attributes in this theme: Theme.AppCompat.Light.DarkActionBar. In particular, I'd like to change the colorPrimary, colorAccent, and colorPrimaryDark attributes based on the data being displayed so that particular widgets like EditTexts can be themed appropriately. I know that I'd have to change the theme before setContentView(...) of my Activity but how do I change particular attributes in the theme before I do that?

Edit: From @reVerse's comment linking to this post I know that it's impossible to change a Theme as they are immutable. Is it possible to create a Theme programmatically?

Community
  • 1
  • 1
Andrew Orobator
  • 7,978
  • 3
  • 36
  • 36
  • 2
    [That's not possible (click for similiar SO-Question)](http://stackoverflow.com/questions/25815769/how-to-really-programmatically-change-primary-and-accent-color-in-android-loll) – reVerse Feb 06 '15 at 17:47
  • Is it possible to create a theme via code? – Andrew Orobator Feb 06 '15 at 17:59
  • 1
    Unfortunately that's also not possible. Your only option is to color each view manually via your code. – reVerse Feb 06 '15 at 18:48
  • If you can live with a fixed-size color palette you can create style overlay definitions and then use [Theme.applyStyle](https://developer.android.com/reference/android/content/res/Resources.Theme.html#applyStyle(int,%20boolean)) to modify the theme at runtime, see my answer to that other SO question. – devconsole Jun 19 '16 at 08:11

0 Answers0