Complete example of the font size and color of the built-in Spinner in the Android system

Source: Internet
Author: User

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
       
     
 



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.