Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
748 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 Reply

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));
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...