0

How does one change the TextView default color throughout the entire app programmatically? Not individual textView but every TextView in all activity layouts

Either getting the current theme and setting the default TextView Color, if <TextView has textColor="" in the xml, then leave it alone.

But if <TextView does not reference a textColor it's getting the default (for the theme) How do I set this based on code/logic

Thanks in advance

TheBearF8
  • 375
  • 1
  • 3
  • 14
  • how about adding an object with the colors you want, and a orientation change listener, and calling getColor with the reference from the object as in get/set color – error86 Nov 18 '20 at 05:17
  • error86: Sounds plausible, should you share a pseudo code idea, thanks – TheBearF8 Nov 18 '20 at 12:38
  • I just realized you can use your app themes to select the colors, this question should help you.https://stackoverflow.com/questions/42139798/how-to-set-textview-text-color-to-specific-theme-color you can of course change the theme at runtime. – error86 Jan 05 '21 at 17:24

1 Answers1

0

Here is the object's code:

object Example {
fun getColor(c: Context) : Int {
    if (someCondition) {
        return (c.getColor(R.color.colorAccent))
    } else {
        return (c.getColor(R.color.colorPrimaryDark))
    }
}

}

you call the get method every time you need to alter the view (you can store the TextViews inside a list)

Alternatively you can use the meterial theme feature that is explained here: https://proandroiddev.com/dark-mode-on-android-app-with-kotlin-dc759fc5f0e1

error86
  • 102
  • 1
  • 10