I'd like to create a bunch of View
s 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 View
s created subsequently with that context)