Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
740 views
in Technique[技术] by (71.8m points)

xamarin.android - To change the color of the spinner text font

I saw this link: https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/spinner

I want to change color of the spinner text font:

<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"/>

But in the output, Color of text is always white.

question from:https://stackoverflow.com/questions/65642302/to-change-the-color-of-the-spinner-text-font

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Option 1. add your custom theme to style.xml. This will change the textcolor of items in the dropdown list. enter image description here

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

layout

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

Option 2. If you want to change the selected item only. 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));
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...