MainActivity is as follows:
Package cc. test; import android. app. activity; import android. OS. bundle; import android. view. view; import android. widget. adapterView; import android. widget. arrayAdapter; import android. widget. spinner; import android. widget. adapterView. onItemSelectedListener;/*** Demo Description: * Complete example of modifying the font size and color of the built-in Spinner in the system ** reference: * http://blog.csdn.net/xuzhuang2008/article/details/7641685 * Thank you very much */public class TestSpinnerActivity extends Activity {private Spinner mSpinner; private ArrayAdapter
MAdapter; private String [] mStringArray; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mSpinner = (Spinner) findViewById (R. id. spinner); mStringArray = getResources (). getStringArray (R. array. test_string_array); // use the custom ArrayAdaptermAdapter = new TestArrayAdapter (TestSpinnerActivity. this, mStringArray); // you can specify the drop-down list style. // mAdapter. setDropDownViewResource (android. r. layout. simple_spinner_dropdown_item); mSpinner. setAdapter (mAdapter); // listens to the mSpinner event selected by the Item. setOnItemSelectedListener (new ItemSelectedListenerImpl ();} private class ItemSelectedListenerImpl implements OnItemSelectedListener {@ Overridepublic void onItemSelected (AdapterView
Parent, View view, int position, long arg3) {System. out. println ("selected:" + mStringArray [position]) ;}@ Overridepublic void onNothingSelected (AdapterView
Parent ){}}}
The TestArrayAdapter is as follows:
Package cc. test; import android. content. context; import android. graphics. color; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. arrayAdapter; import android. widget. textView; public class TestArrayAdapter extends ArrayAdapter
{Private Context mContext; private String [] mStringArray; public TestArrayAdapter (Context context, String [] stringArray) {super (context, android. r. layout. simple_spinner_item, stringArray); mContext = context; mStringArray = stringArray;} @ Overridepublic View getDropDownView (int position, View convertView, ViewGroup parent) {// modify the font color of the expanded Spinner if (convertView = null) {LayoutInflater inflater = LayoutInflater. from (mContext); convertView = inflater. inflate (android. r. layout. simple_spinner_dropdown_item, parent, false);} // text1 is the default TextViewTextView TV = (TextView) convertView used by the Spinner to display text. findViewById (android. r. id. text1); TV. setText (mStringArray [position]); TV. setTextSize (22f); TV. setTextColor (Color. RED); return convertView ;}@ Overridepublic View getView (int position, View convertView, ViewGroup parent) {// modify the font color of the result after the selection of the Spinner if (convertView = null) {LayoutInflater inflater = LayoutInflater. from (mContext); convertView = inflater. inflate (android. r. layout. simple_spinner_item, parent, false);} // text1 is the default TextViewTextView TV = (TextView) convertView used to display text. findViewById (android. r. id. text1); TV. setText (mStringArray [position]); TV. setTextSize (18f); TV. setTextColor (Color. BLUE); return convertView ;}}
Main. xml is as follows:
Arrays. xml is as follows:
None
Insomnia
Anemia
Hair loss
Exhausted
Irritability
Fattier
Thin
White hair
Headache
Myopia
Amblyopia
Tinnitus