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.