我試圖讓我的地圖視圖返回到正常樣式,當我將片段內的開關撥到OFF位置但它不工作。以下是我面對的過程期間所發生的情況:MapView在點擊切換開關後沒有恢復到正常狀態
- 片段(方含地圖)和開關出現
- 輕彈開關置於ON位置
- 樣式化地圖出現
- 輕彈開關置於OFF位置
- 地圖不改變
我試着用mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
但地圖仍然被困在馬風格當我輕彈開關時,可以看到p視圖。不確定發生了什麼問題。必須做些什麼來解決這個問題?
public class FragmentMap extends android.support.v4.app.Fragment implements OnMapReadyCallback {
private SwitchCompat swt;
public FragmentMap() {
}
GoogleMap mGoogleMap;
MapView mMapView;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_map, container, false);
mMapView = (MapView) v.findViewById(R.id.map_park);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
swt = (SwitchCompat) v.findViewById(R.id.switch_map_park);
swt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
boolean success = mGoogleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("TabFragmentMap", "Style parsing failed.");
}
}else{
// What goes here?
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
});
return v;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
mGoogleMap.setBuildingsEnabled(true);
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
}
不幸的是,我以前從來沒有使用可穿戴設備。 – MohanadMohie