Text Color Spinner for Android
I have a Spinner and I am using SimpleCursorAdapter to fill it. I want the font color for the inker to be black and the font color for drop out to be white. I have this code:
String[] column = { "name" };
int[] viewIds = new int[] { R.id.spinner_dropdown_design_from };
SimpleCursorAdapter fromListAdapter = new SimpleCursorAdapter(MyClass.this, R.layout.spinner_drop_down_from, cursor,
column, viewIds) {
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View viewFromListAdapter = super.getDropDownView(position, convertView, parent);
if (position % 2 == 0) {
viewFromListAdapter.setBackgroundResource(R.layout.dropdown_selector_odd);
} else {
viewFromListAdapter.setBackgroundResource(R.layout.dropdown_selector_even);
}
return viewFromListAdapter;
}
};
So I am using a different layout for the odd and even lines in the dropdown. I am giving you an example for dropdown_selector_even
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/grey_background"/>
<item android:state_focused="true" android:drawable="@drawable/blue_background"/>
<item android:state_pressed="true" android:drawable="@drawable/blue_background"/>
<item android:drawable="@drawable/grey_background"/>
</selector>
And spinner_drop_down_from
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_dropdown_design_from"
android:layout_height="100dip"
android:layout_width="fill_parent"
android:paddingLeft="20dip"
android:textSize="40dip"
android:gravity="center_vertical"
android:textStyle="normal|bold"
android:textColor="#000000"/>
Can anyone help me? Thanks in advance!
+3
source to share
2 answers
I found a solution. I also have to overwrite the getView method Something like this
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(R.id.spinner_dropdown_design_products);
text.setTextColor(Color.WHITE);
return view;
}
+6
source to share
Please take a look at the following link. This worked for me and no need to use custom adapters. Just xml. http://www.broculos.net/2013/09/how-to-change-spinner-text-size-color.html#.U2eJI_l5OSo
+2
source to share