我已经在AlertDialogBuilder中创建了MapView。
但是当地图显示太暗而且很难看到时。 有谁能帮我解决这个问题?
我只是希望地图是正常的,就像我们在活动或片段中显示地图一样
这是我的活动代码:
private void showCustomAlert(String param){
LayoutInflater inflater = getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.customDialog));
AlertDialog alertDialog = builder.create();
switch (param){
... //other case code whith break point
case "String Param" :
final View rootMV = inflater.inflate(R.layout.custom_alert_maps, null);
alertDialog.setView(rootMV);
MapView mV = rootMV.findViewById(R.id.my_mv_id);
mV.onCreate(alertDialog.onSaveInstanceState());
mV.onResume();
mV.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng myll = new LatLng(-0.998812,109.784933);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(myll)
.zoom(18)
.build();
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
googleMap.setMyLocationEnabled(true);
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
googleMap.addMarker(new MarkerOptions().position(myll).title("Place Name"));
try {
MapsInitializer.initialize(getBaseContext());
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
} catch (Exception e) {
e.printStackTrace();
}
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
googleMap.getUiSettings().setZoomControlsEnabled(true);
}
});
alertDialog.show();
break;
}
}
这是我的自定义布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tv_title_view_maps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="18sp"
android:textColor="@color/colorAccent"
android:text="Location"/>
<com.google.android.gms.maps.MapView
android:id="@+id/my_mv_id"
android:layout_width="match_parent"
android:layout_height="380dp"
android:layout_below="@+id/tv_title_view_maps"
android:layout_margin="6dp"
style="@style/customDialog"/>
</RelativeLayout>
这是我的自定义样式:
<style name="customDialog" parent="ThemeOverlay.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
这是结果: MapView too dark
提前致谢
答案 0 :(得分:0)
<强>解决强>
我感谢@Ridcully的回答
它只是将自定义样式设置为relativeLayout
来自:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tv_title_view_maps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="18sp"
android:textColor="@color/colorAccent"
android:text="Location"/>
<com.google.android.gms.maps.MapView
android:id="@+id/my_mv_id"
android:layout_width="match_parent"
android:layout_height="380dp"
android:layout_below="@+id/tv_title_view_maps"
android:layout_margin="6dp"
style="@style/customDialog"/>
</RelativeLayout>
是这样的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/customDialog">
<TextView
android:id="@+id/tv_title_view_maps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="18sp"
android:textColor="@color/colorAccent"
android:text="Location"/>
<com.google.android.gms.maps.MapView
android:id="@+id/my_mv_id"
android:layout_width="match_parent"
android:layout_height="380dp"
android:layout_below="@+id/tv_title_view_maps"
android:layout_margin="6dp"/>
</RelativeLayout>