通过编程设置包含android:textColor和android:background的样式?(Xamarin.Android)

通过编程设置包含android:textColor和android:background的样式?(Xamarin.Android),xamarin.android,attributes,set,styles,programmatically,Xamarin.android,Attributes,Set,Styles,Programmatically,我在styles.xml中有以下样式: <style name="tabSelected"> <item name="android:textColor">#FFFFFF</item> <item name="android:background">#0000ff</item> </style> <style name="tabUnselected"> <item name="an

我在
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>
但是它只改变了
textview
textColor
。我看到了另一种解决方案:

ContextThemeWrapper newContext = new ContextThemeWrapper(baseContext, R.style.MyStyle);
textView= new TextView(newContext);
但它正在创建一个新的
TextViews
实例,我不知道它的
click
事件在此之后是否会起作用,而且它是两行解决方案,如果它将是两行,我最好:

multipurposeRoomTextView.SetTextColor(#ffffff);
multipurposeRoomTextView.SetBackgroundColor(#0000ff);

它将更具可读性。这是一种通过编程方式使用一个属性设置样式的方法,类似于
multipurposeRoomTextView.SetStyle(MyStyle)

parent=“@android:style/Widget.TextView”
添加到
style
中,并使用
settextearance
方法。和你第一次一样attempt@Montoolivo,我搜索了一些关于TextView.SetTextAppearance方法的文章,它似乎不能用于更改所有属性,ContextThemeWrapper在创建新视图时可以工作,并且似乎不适用于现有视图,下面是您可以查看的相同线程:
multipurposeRoomTextView.SetTextColor(#ffffff);
multipurposeRoomTextView.SetBackgroundColor(#0000ff);