【问题标题】:How to change the Text color of Spinner [duplicate]如何更改 Spinner 的文本颜色 [重复]
【发布时间】:2013-01-27 19:52:29
【问题描述】:

请帮助我更改微调器的文本颜色。

【问题讨论】:

标签: android spinner


【解决方案1】:

试试这个

custom_spinner_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top"
    android:singleLine="true"
    android:textColor="@color/iphone_text" />

在 Java 代码中

Spinner spnCategory= (Spinner)findViewById(R.id.my_spinner);

..

ArrayAdapter<String> adptSpnCategory = new ArrayAdapter<String>this,R.layout.custom_spinner_item, alCategoryName);
adptSpnCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnCategory.setAdapter(adptSpnCategory);
spnCategory.setOnItemSelectedListener(new OnItemSelectedListener() 
{
 public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
 {
 }
 public void onNothingSelected(AdapterView<?> arg0) 
 {
 }
});

【讨论】:

  • 但它也会增加微调器的大小。就我而言,我制作了透明的微调器视图并将其放置在更靠近视图的位置。因此,如果按照上面提到的方法,它也会影响微调器对话框和微调器视图大小......还有其他建议吗?
【解决方案2】:

试试这个:

 Spinner spinner = (Spinner)findViewById(R.id.my_spinner);
    TextView tv = (TextView) spinner.getSelectedView();
    tv.setTextColor(Color.BLACK);

否则在 spinner_xml 中更改:

 <?xml version="1.0" encoding="utf-8"?>

<TextView  
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"
     android:textSize="20dip"
     android:gravity="left"  
     android:textColor="#FF0000"         
     android:padding="5dip"
/>

【讨论】:

  • 小心,getSelectedView() 应该在选择项目后调用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-07
  • 1970-01-01
  • 2011-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-12
相关资源
最近更新 更多