更改微调文本字体的颜色

问题描述

我看到了这个链接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。这将更改下拉列表中项目的文本颜色。 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));
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...