Today needs to change a actionbar on the spinner font color, the results have not been solved for a long time, and finally found that he is in the code to add a TextView, and then use adapter loaded, not directly under the framework of the layout. Now summarize the use of spinner, see the following code directly
1) First, you need to have a spinneradapter to load the data with spinner.
PrivateBaseadapter Mstackadapter =NewBaseadapter () {@Override Public intGetCount () {returnmState.stack.size (); } @Override PublicDocumentinfo GetItem (intposition) { returnMState.stack.get (MState.stack.size ()-position-1); } @Override Public LongGetitemid (intposition) { returnposition; } @Override PublicView GetView (intposition, View Convertview, ViewGroup parent) { if(Convertview = =NULL) {Convertview=Layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.item_title, parent,false); } FinalTextView title =(TextView) Convertview.findviewbyid (Android. R.id.title); FinalDocumentinfo doc =GetItem (position); if(Position = = 0) { FinalRootinfo root =Getcurrentroot (); Title.settext (Root.title); } Else{title.settext (doc.displayname); } //No padding when shown in ActionbarConvertview.setpadding (0, 0, 0, 0); returnConvertview; } @Override PublicView Getdropdownview (intposition, View Convertview, ViewGroup parent) { if(Convertview = =NULL) {Convertview=Layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.item_title, parent,false); } FinalImageView subdir =(ImageView) Convertview.findviewbyid (R.id.subdir); FinalTextView title =(TextView) Convertview.findviewbyid (Android. R.id.title); FinalDocumentinfo doc =GetItem (position); if(Position = = 0) { FinalRootinfo root =Getcurrentroot (); Title.settext (Root.title); Subdir.setvisibility (View.gone); } Else{title.settext (doc.displayname); Subdir.setvisibility (view.visible); } returnConvertview; } };
There are two more important methods.
One is GetView: This method is loaded with hints for prompt
One is Getdropview: This is for loading the dropdown box
2) Add Dropview Click to listen for events
PrivateOnnavigationlistener Mstacklistener =NewOnnavigationlistener () {@Override Public BooleanOnnavigationitemselected (intItemposition,LongitemId) { if(mignorenextnavigation) {mignorenextnavigation=false; return false; } while(MState.stack.size () > itemposition + 1) {mstate.stacktouched=true; MState.stack.pop (); } oncurrentdirectorychanged (ANIM_UP); return true; } };
3) Add Spinneradapter and Dropview
-1);
Actionbar spinner-Usage Examples