Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set different themes for inflated layout in a view stub

Tags:

android

I have a layout that I'm inflating into a ViewStub. When its within view A, I want to have one set of styles applied to the EditText fields, and when it's within view B, I want to have a different set of styles applied to the EditText fields.

First, is this possible, and second (if so), how would I go about it?

like image 684
Travis Avatar asked Jul 22 '14 17:07

Travis


1 Answers

I'm not sure about ViewStubs specifically, but if you wanted to inflate a predefined layout and add it to a ViewGroup you could use a ContextThemeWrapper.

View viewOne = View.inflate(new ContextThemeWrapper(context, R.style.Theme_One), R.layout.my_layout)
View viewTwo = View.inflate(new ContextThemeWrapper(context, R.style.Theme_Two), R.layout.my_layout)
like image 176
jimmithy Avatar answered Sep 23 '22 00:09

jimmithy