I am working on an android application Menu with Action Bar, I want to put the dropdown menu in the action bar like the one present in Google Maps application.
check this Link also it is helpful example Example link
GoogleMap map;
TextView txt;
String[] mapTypes={"Normal","Hybrid","Satellite","Terrain"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
txt=(TextView)findViewById(R.id.textView1);
//to set map Type
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//To set the marker on map on specific location using lat lag
// latitude and longitude
double latitude = 18.520430300000000000;
double longitude = 73.856743699999920000;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("My Location");
// change color to the marker icon
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
// adding marker
map.addMarker(marker);
// Create an array adapter to populate dropdownlist
ArrayAdapter adapter =new ArrayAdapter(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, mapTypes);
/** Enabling dropdown list navigation for the action bar */
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
/** Defining Navigation listener */
ActionBar.OnNavigationListener navigationListener=new ActionBar.OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Toast.makeText(getBaseContext(), "U Select : "+mapTypes[itemPosition], Toast.LENGTH_SHORT).show();
if (mapTypes[itemPosition].equals("Normal")) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
else if (mapTypes[itemPosition].equals("Hybrid")) {
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
else if (mapTypes[itemPosition].equals("Satellite")) {
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
else if (mapTypes[itemPosition].equals("Terrain")) {
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
}
return false;
}
};
// Setting dropdown items and item navigation listener for the actionbar
getActionBar().setListNavigationCallbacks(adapter, navigationListener);
}