First of all, why use Tintspinner instead of spinner?
See Several compatibility issues with the APPCOMPAT_V7 21.0.0d
And then we're going to customize the effect is
That is, the selected style is white text, the drop-down style is black text, such a small need, also need skill.
First of all, Tintspinner adapter need to use Arrayadapter, and not use Baseadapter, before I go the detour is to use Baseadapter and then looking for
Adapter. Setdropdownviewresource (R.layout. Drop_down_item );
method, the result is obviously easy to see, Baseadapter is not this method, why?
Because Baseadapter implements the ListAdapter, the Spinneradapter interface:
Public abstract class Baseadapter implements ListAdapter, Spinneradapter
And Arrayadapter is the Baseadapter subclass.
public class Arrayadapter<t> extends Baseadapter implements Filterable
So I see that I can't find the Setdropdownviewresource method.
Doubts lifted, the following see how the realization of this adapter:
Model for
public class Endemicarea { @JsonField ("description") private String description; @JsonField ("name") private String name; @JsonField ("PK") private int pk; Public Endemicarea (string description, string name, int pk) { this.description = description; this.name = name; this.pk = PK; } Public String getdescription () { return description; } public void SetDescription (String description) { this.description = description; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; } public int getpk () { return pk; } public void setpk (int pk) { this.pk = PK; }}
Adapter is:
public class Endemicareaspinneradapter extends arrayadapter<endemicarea> {private Layoutinflater Layoutinflater ; Public Endemicareaspinneradapter (context context, int resource, list<endemicarea> endemicarealist) {Super (CO ntext, resource, endemicarealist); Layoutinflater = Layoutinflater.from (context); } @Override public view getView (int position, view Convertview, ViewGroup parent) {View view = Layoutinflate R.inflate (R.layout.choose_bed_item, NULL); TextView areaname = (TextView) View.findviewbyid (r.id.choose_bed_item_name); Areaname.settext (GetItem (position). GetName ()); return view; } @Override public view getdropdownview (int position, view Convertview, ViewGroup parent) {View view = Layou Tinflater.inflate (Android. R.layout.simple_spinner_dropdown_item, parent, false); Checkedtextview areaname = (checkedtextview) View.findviewbyid (Android. R.ID.TEXT1); Areaname.settext (GetItem (position). GetName ()); return view; }}
Choose_bed_item.xml for
<?xml version= "1.0" encoding= "Utf-8"? ><textview xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/choose_bed_item_name " android:layout_width=" match_parent " android:layout _height= "Wrap_content" android:layout_margin= "4DP" android:gravity= "center" android:paddingbottom= "10DP" android:layout_marginright= "8DP" android:paddingtop= "10DP" android:textcolor= "@color/white" android:textsize= "20SP" ></TextView>
finally:
Tintspinner = new Tintspinner (getactivity ()); Tintspinner.setbackgroundresource (R.drawable.abc_spinner_mtrl_am_alpha); Tintspinner.setadapter (Spinneradapter);
Note: tintspinner, import android.support.v7.internal.widget.TintSpinner;
It seems that spinner needs arrayadapter to customize the drop-down style, and then it can be fully customizable.
Customizing the style of the Tintspinner