I have the following styles in styles.xml :
<style name="tabSelected">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#0000ff</item>
</style>
<style name="tabUnselected">
<item name="android:textColor">#0000ff</item>
<item name="android:background">#FFFFFF</item>
</style>
And I have two TextViews in my activity. When I click the first TextView I want to add the style tabSelected to it and to remove tabUnselected from it and when I click the second TextView I want to add the style tabSelected to it and to remove tabUnselected from it:
I tried the following:
exhibitionAreaTextView.Click += delegate
{
exhibitionAreaTextView.SetTextAppearance(Resource.Style.tabSelected);
multipurposeRoomTextView.SetTextAppearance(Resource.Style.tabUnselected);
};
multipurposeRoomTextView.Click += delegate
{
multipurposeRoomTextView.SetTextAppearance(Resource.Style.tabSelected);
exhibitionAreaTextView.SetTextAppearance(Resource.Style.tabUnselected);
};
But it changed only the textColor of the TextViews. I've seen another solution:
ContextThemeWrapper newContext = new ContextThemeWrapper(baseContext, R.style.MyStyle);
textView= new TextView(newContext);
But it is making a new instance of the TextViews and I don't know if its click event will work after that and more it is 2 lines solution, if it's going to be 2 lines, I better put:
multipurposeRoomTextView.SetTextColor(#ffffff);
multipurposeRoomTextView.SetBackgroundColor(#0000ff);
It will be more readable. Is it a way to set the style with one property programatically, something like that multipurposeRoomTextView.SetStyle(MyStyle)?