// 在初始化之前改变 Spinner文字标题颜色 mySpinner.xml 样式文件放在main.xml 同一目录
mySpinner.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:gravity="left"
android:paddingLeft="8dip"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="12dip"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee" />
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.mySpinner.xml, curs); //此处加上自己的样式
效果如下:
// 初始化完了后改变 Spinner文字标题颜色
private void setCursListener(String[] curs, int select, boolean monitor) {
Spinner spinner = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, curs);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setSelection(select);
if(monitor){
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id){
curyid = position;
//showPrice(position);
TextView tv = (TextView)view;
tv.setTextColor(getResources().getColor(R.color.white)); //设置颜色
tv.setTextSize(12.0f); //设置大小
tv.setGravity(android.view.Gravity.CENTER_HORIZONTAL); //设置居中
}
@Override
public void onNothingSelected(AdapterView<?> parent){}
});
}
}