I've created a spinner, from where a user can select a value. I CAN change the textcolor of the spinner itself like shown in this picture:
Unfortunately when I press the spinner a list of items, to be selected, is shown, but these have a white font color on white background, and I just haven't been able to change this:
I've googled the problem and others have experienced the same problem. None of the fixes suggested worked for me. As far as I understand I have to make a custom list of some kind, but well.. I'm not able to make it work. Any suggestions?
My code looks like this (array_spinner is a array of strings):
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, array_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
And my row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:textSize="14dp" />
Try this (untested). I'm basically reproducing simple_spinner_dropdown_item.xml
but with a black text color:
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, array_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
with
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, array_spinner);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
res/layout
, called spinner_dropdown_item.xml
:<CheckedTextView
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#FF000000"
/>
Simple and Crisp
private OnItemSelectedListener your_spinner _name = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
}
public void onNothingSelected(AdapterView<?> parent) {
}
};
I was having this same issue. My answer isn't the most proper answer, but it's a very quick solution for those using a basic app theme.
If you are creating the arrayadapter for the spinner using
createfromResource()
Do NOT use getApplicationContext(). Declare Myclass.this instead. My text now stays the same as the basic app theme. Hopefully this will help someone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With