I\'m having an issue with the Droid X phones where users say that the font color turns out to be white in the spinner, making it invisible unless the users highlight the ite
Simple and Crisp ...
private OnItemSelectedListener OnCatSpinnerCL = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
((TextView) parent.getChildAt(0)).setTextSize(5);
}
public void onNothingSelected(AdapterView<?> parent) {
}
};
write a R.layout.simplespinneritem:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The ID is android:id="@android:id/text1"
, set the color of font and background.
ArrayAdapter adapter =
new ArrayAdapter(this,packagename.R.layout.simple_spinner_item, spin_arry);
To add to sasad's reply, make a copy of that file, which you can find in your Android folder, in your project, change the text color of the TextView in that file, and use that layout while initializing the Adapter instead of android's.
You could try this approach too wherein you add 2 new Layout Resource Files
and use them in the code .
String spin_arry[] = new String[str_vec.size()];
str_vec.copyInto(spin_arry);
ArrayAdapter adapter =
new ArrayAdapter(this,R.layout.custom_simple_spinner_item, spin_arry);
adapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
custom_spinner_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
style="?attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fontFamily="@font/roman"
android:singleLine="true"
android:textAlignment="inherit"
android:textColor="@color/black"
android:textSize="14sp">
</TextView>
custom_spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
style="?attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:ellipsize="marquee"
android:fontFamily="@font/roman"
android:singleLine="true"
android:textAlignment="textStart"
android:textColor="@color/black"
android:textSize="14sp">
</TextView>
Happy Coding !! :)
public class ee extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.ww);
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection(){
ArrayList<String> array = new ArrayList<String>();
array.add("item0");
Spinner spinner1;
ArrayAdapter<String> mAdapter;
spinner1= (Spinner) findViewById(R.id.spinner2);
spinner1= new ArrayAdapter<String>(this, R.layout.spinner_item, array);
spinner1.setAdapter(mAdapter);
}
}
and in xml res/layout add new xml file: type layout, spinner
(in spinner_item.xml)
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:singleLine="true"
android:textColor="#00f0ff" />
make your own layout xml file, and give a android:textColor="#000" for black text