问题描述
我看到了这个链接: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. 将您的自定义主题添加到 style.xml。这将更改下拉列表中项目的文本颜色。
<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"/>
...
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));
}