问题
I am currently trying, in addition of the amazing ActionBerSherlock library to add a spinner navigation menu in my application (like Google Maps)
Note: I have been thinking also about the SPotify/Evernote/Facebook pattern, but that seems inappropriate on Android: http://alexanderblom.se/2012/04/23/android-navigation-and-spotify/
I have already worked on the spinner (http://developer.android.com/design/building-blocks/spinners.html), but adding an icon seems not so easy
Thank a lot for any link or help on this menu...
回答1:
First you need to create a CustomArrayAdapter for your spinner. It should handle both, an array of Strings and an array of Drawables. In your case perhaps a second array for a little summary.
Then you'll need a layout for the item with the ImageView for the icon and a TextView for the text (and perhaps one for the summary). Override the getView() and the getDropDownView() to fill your layout with the resources handed in (createFromResource() might be a method to look into).
For the Navigation, all you need to do is to create the CustomArrayAdapter in your onCreate() with the arrays of resources, call MyActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST) and feed the Navigation with your CustomArrayAdapter via MyActionBar.setListNavigationCallbacks(list, this).
回答2:
One would assume that one would use the Android Adapter
pattern, with that adapter containing a list, of sorts (perhaps an ArrayList
?), of the items that you want to display (in this case, an icon, a title string and a subtitle string).
Take a look at extending some sort of SpinnerAdapter
; presumably you'll also then need to create a layout for each item that contains both the icon and the two TextView
s.
来源:https://stackoverflow.com/questions/10649786/actionbar-spinner-with-an-icon-like-google-maps-how-can-i-achieve-that