我无法在微调窗口小部件上设置颜色.怎么样?
解决方法
尝试使用此适配器作为您的微调:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Home.Home_Group,R.layout.my_spinner_style,yourstringarray) { public View getView(int position,View convertView,ViewGroup parent) { View v = super.getView(position,convertView,parent); ((TextView) v).setTextSize(16); ((TextView) v).setTextColor( getResources().getColorStateList(R.color.white) ); return v; } public View getDropDownView(int position,ViewGroup parent) { View v = super.getDropDownView(position,parent); v.setBackgroundResource(R.drawable.spinner_bg); ((TextView) v).setTextColor( getResources().getColorStateList(R.color.spinner_text) ); ((TextView) v).setTypeface(fontStyle); ((TextView) v).setGravity(Gravity.CENTER); return v; } };
将此xml添加到布局中,
my_spinner_style.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/text1" style="?android:attr/spinnerItemStyle" android:singleLine="true" android:textColor="#ffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ellipsize="marquee" />
最后,
spinner.setAdapter(adapter);