Implementation of effects (source code implementation) of custom Spinner styles in Android Development

Source: Internet
Author: User

Implementation of effects (source code implementation) of custom Spinner styles in Android Development

The built-in Spinner style of the android system is far from satisfying the requirements of the Spinner UI style in our actual development process. Therefore, we must modify our Spinner style to suit the style of the entire application. The system provides two common modification methods: XML static and Java code dynamic, this article mainly describes how to dynamically modify the style of a Spinner. My implementation method is to construct a SpinnerAdapter by myself, inherit from ArrayAdapter, override getDropDownView (), getView (), and other methods are not critical, there is no big difference with other ListView and so on. Now let's look at the code parsing!

Package com. example. account. add; import android. content. context; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. arrayAdapter; import android. widget. textView; public class SpinnerAdapter extends ArrayAdapter <String> {private Context mContext; private String [] mStringArray; public SpinnerAdapter (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); // We can also load our Layout convertView = inflater. inflate (android. r. layout. simple_spinner_dropdown_item, parent, false);} TextView TV = (TextView) convertView. findViewById (android. r. id. text1); TV. setText (mStringArray [position]); TV. setTextSize (15); return convertView;} @ Overridepublic View getView (int position, View convertView, ViewGroup parent) {// modify the font color of the result selected by the Spinner if (convertView = null) {LayoutInflater inflater = LayoutInflater. from (mContext); convertView = inflater. inflate (android. r. layout. simple_spinner_item, parent, false);} // here, text1 is the TextViewTextView TV = (TextView) convertView used by the Spinner system to display text. findViewById (android. r. id. text1); TV. setText (mStringArray [position]); TV. setTextSize (15); return convertView ;}}



How does android change the spinner style?

Reference: blog.csdn.net/..587953
I don't know what you mean.

In android development, how can we associate three sinkers? For example, if the source code is sent to 466315004 @ qqcom

I 've done it before and forgot it. You can see the following code,

Public void func (){
ArrayAdapter <String> shopAdapter = new ArrayAdapter <String> (this, android. R. layout. preference_category, shop_temp );
ShopAdapter. setDropDownViewResource (android. R. layout. simple_spinner_dropdown_item );
ShopSp. setAdapter (shopAdapter );
}

A long time ago, after a city was selected, the spinner automatically checked the store in the city.

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.