How to change the Text color of Spinner [duplicate]

放肆的年华 提交于 2019-12-18 04:26:14

问题


Please help me on changing the text color of the spinner.


回答1:


Try this

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

In Java code

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:


try this:

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

otherwise change in 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"
/>


来源:https://stackoverflow.com/questions/14833714/how-to-change-the-text-color-of-spinner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!