Reputation: 385
I have a spinner. I have retrieved my contents in the SPINNER from the database and bind it to the Spinner. But my problem is the Background-color of the pop up of the the Spinner window is white and also the font color for the contents is also white. So I am not able to view the contents in the window apart from selected.
How to set the font color for the Spinner ?
Below is the Activity Code:
I have a spinner. I have bind my contents in the SPINNER from the array to the Spinner.
String bloodgroups[]={
"A +ve" "B +ve"
};
Spinner spinner=(Spinner)findViewById(R.id.spin);
ArrayAdapter<String> adapter=new ArrayAdapter<String> this,android.R.layout.simple_dropdown_item_1line,bloodgroups);
spinner.setAdapter(adapter);
But my problem is the Background-color of the pop up of the the Spinner window is white and also the font color for the contents is also white. So I am not able to view the contents in the window apart from selected.
How to set the font color for the Spinner ?
Below is the file attached :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tc"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:freezesText="false"
android:text="Enter Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:typeface="monospace" />
<EditText
android:id="@+id/txtname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Date of Birth"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/txtdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="date" />
<Button
android:id="@+id/btnseldate"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date" />
</TableRow>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Blood Group"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Address"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtadd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPostalAddress" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter ContactNo. "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
<Button
android:id="@+id/btnadd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit Details" />
<Button
android:id="@+id/btndisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Details" />
</LinearLayout>
</ScrollView>
Below is the file attached :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tc"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:freezesText="false"
android:text="Enter Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:typeface="monospace" />
<EditText
android:id="@+id/txtname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Date of Birth"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/txtdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="date" />
<Button
android:id="@+id/btnseldate"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date" />
</TableRow>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Blood Group"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Address"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtadd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPostalAddress" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter ContactNo. "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
<Button
android:id="@+id/btnadd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit Details" />
<Button
android:id="@+id/btndisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Details" />
</LinearLayout>
</ScrollView>
Upvotes: 1
Views: 1784
Reputation: 3485
you need to create you custom adapter with the creation of views in drop down list:
static class CustomArrayAdapter<T> extends ArrayAdapter<T>
{
public CustomArrayAdapter(Context ctx, T [] objects)
{
super(ctx, android.R.layout.simple_spinner_item, objects);
}
//other constructors
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
//we know that simple_spinner_item has android.R.id.text1 TextView:
/* if(isDroidX) {*/
TextView text = (TextView)view.findViewById(android.R.id.text1);
text.setTextColor(Color.RED);//choose your color :)
/*}*/
return view;
}
}
And to use:
this.mAdapter = new CustomArrayAdapter<CharSequence>(this, bloodgroups);
Upvotes: 1
Reputation: 21191
simple_spinner_item.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="20dp"
android:textSize="25dp"
android:layout_marginTop="15dp"/>
and in your activity
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,R.layout.simple_spinner_item);
//adapter.add();====> Add items to the adapter here
spinner.setAdapter(adapterGender);
Upvotes: 0