0

I'd like to create a bunch of Views with a context that is based on some style, but also some dynamically calculated overrides. I'd like to create a Context that encapsulates all that, so that I can pass that to various different View constructors.

To make my question more complete, without the dynamic part, I'd be using a ContextThemeWrapper like this:

// in my onCreate
Context styling = new ContextThemeWrapper(this, R.style.TextBase_OutputText);
View v1 = TextView(styling);
View v2 = Button(styling);
// and so on

But I'd instead like to do this:

// in onCreate
Context styling = new ContextWrapperThatImLookingFor(new ContextThemeWrapper(this, R.style.TextBase_OutputText));
styling.addOverride(textColor, computeForegroundColorDynamically()); // ???
View v1 = TextView(styling);
// and so on

How do I achieve this?

(note that this question is about the Android platform, not about any Kotlin or Java language feature as a commenter suggested -- ContextWrapperThatImLookingFor would be a simple subclass of Context that I can add overrides to that are then applied to Views created subsequently with that context)

Cactus
  • 27,075
  • 9
  • 69
  • 149
  • You cannot have `constructors` as extensions for any class as of yet in kotlin check this answer https://stackoverflow.com/questions/46582809/is-it-possible-to-create-extension-constructors-in-kotlin – HawkPriest Jul 02 '18 at 15:50
  • No this is not about any Kotlin language feature. The question would work just as well with Java or any other language. The question is about the Android platform, and how I can make a `Context` which uses a style plus programmatic overrides. – Cactus Jul 03 '18 at 10:37

0 Answers0