【问题标题】:To change the color of the spinner text font更改微调器文本字体的颜色
【发布时间】:2021-01-09 11:54:53
【问题描述】:

我看到了这个链接: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"/>

但是在输出中,文本的颜色总是白色的。

【问题讨论】:

    标签: xamarin.android android-spinner textcolor


    【解决方案1】:

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

    选项 2。如果您只想更改所选项目。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      相关资源
      最近更新 更多