更改微调文本字体的颜色

时间:2021-01-09 11:54:53

标签: xamarin.android android-spinner textcolor

我看到了这个链接:https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/spinner

我想更改微调文本字体的颜色:

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown"
    android:textColor="#FF0080FF"
    android:popupBackground="#FF553232"
    android:background="#FFD733D7"/>

但在输出中,文本的颜色始终为白色。

1 个答案:

答案 0 :(得分:1)

选项 1. 将您的自定义主题添加到 style.xml。这将更改下拉列表中项目的文本颜色。 enter image description here

<style name="MySpinnerTheme" parent="android:Theme">
   <item name="android:textColor">@android:color/holo_green_dark</item>
</style>

布局

<Spinner
   android:id="@+id/spinner1"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:theme="@style/MySpinnerTheme"
   android:spinnerMode="dropdown"/>

选项 2。如果您只想更改所选项目。 enter image description here


...

Spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);

...

private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e){
   Spinner spinner = (Spinner)sender;
   TextView textView = (TextView)spinner.SelectedView;
   
   textView.SetTextColor(Color.Rgb(0, 235, 0));
}
相关问题