I\'m trying to show a MapFragment
of the Android Maps v2 API
in an Activity
with the @android:style/Theme.DeviceDefault.Light.Di
To add on to Audrel's solution, one can dynamically un-dim the dialog's window whenever the map is shown and dim it back when the map is gone (e.g. when your dialog has multiple pages, one of them is a map):
private float mDimAmount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WindowManager.LayoutParams params = getWindow().getAttributes();
mDimAmount = params.dimAmount; // remember original dim amount
...
}
private void undim() {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.dimAmount = 0.0f;
getWindow().setAttributes(params);
}
private void dim() {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.dimAmount = mDimAmount;
getWindow().setAttributes(params);
}
Still just another workaround rather than tackling the root cause...
Simply add this line to your style !
<item name="android:backgroundDimEnabled">false</item>
This is my style :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/dark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="windowActionBar">false</item>
</style>
Depending on what your purpose is for the map in the dialog, if you don't need any of the map controls, you can use liteMode
in which just an image of the map is displayed with whatever location you load. It doesn't have this z-layer overlay problem.
You can add this to the MapView
layout xml:
map:liteMode="true"
This worked for me, because I didn't want my map to be interactive anyway.
You can read the Google docs here: https://developers.google.com/maps/documentation/android-api/lite
I got the same problem. After some research, I found two hacks :
<item name="android:backgroundDimEnabled">false</item>
Bad part : it removes the black overlays behind the activity.
GoogleMapOptions googleMapsOptions = new GoogleMapOptions();
googleMapsOptions.zOrderOnTop( true );
MapFragment mapFragment = MapFragment.newInstance(googleMapsOptions);
Bad part : The map is above the Zoom control and MyLocation button.
Personnaly, I choose the first solution.
Hope this help !
Link to the source
For DialogFragment
:
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);