ActionBar spinner with an icon (like Google Maps), how can I achieve that?

本小妞迷上赌 提交于 2020-01-01 18:16:08

问题


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



来源:https://stackoverflow.com/questions/10649786/actionbar-spinner-with-an-icon-like-google-maps-how-can-i-achieve-that

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!