AlertDialog.Builder 中的 MapView 显示太暗



我已经在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>

结果如下: 地图视图太暗

提前致谢

已解决

我感谢@Ridcully的回答

它只是将自定义样式设置为相对布局

由此:

<?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>

最新更新