设置右侧菜单
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_map_menu, menu); return true; }
menu布局文件
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <group> <item android:id="@+id/menu_map_normal" android:title="@string/map_menu_normal" app:showAsAction="never" /> <item android:id="@+id/menu_map_satellite" android:title="@string/map_menu_satellite" app:showAsAction="never" /> <item android:id="@+id/menu_map_none" android:title="@string/map_menu_none" app:showAsAction="never" /> </group> </menu>
menu菜单监听 同toolbar返回监听
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: this.finish(); case R.id.menu_map_normal: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); break; case R.id.menu_map_satellite: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); break; case R.id.menu_map_none: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NONE); break; default: return true; } return super.onOptionsItemSelected(item); }