ActionBar spinner with an icon (like Google Maps),

2019-04-13 00:39发布

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/

enter image description here

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...

2条回答
男人必须洒脱
2楼-- · 2019-04-13 01:40

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).

查看更多
smile是对你的礼貌
3楼-- · 2019-04-13 01:45

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 TextViews.

查看更多
登录 后发表回答