Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapFragment gets a dark overlay when used in DialogActivity

I'm trying to show a MapFragment of the Android Maps v2 API in an Activity with the @android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar theme. This works fine. However, the map gets a dark overlay:

Dialog

When I change the theme to @android:style/Theme.DeviceDefault.Light.NoActionBar, the map is shown as it should:

Normal

This is my xml layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        class="com.google.android.gms.maps.MapFragment" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="HELLO"
        android:textSize="@dimen/textsize_large" />

</LinearLayout>

What is happening here?

like image 642
nhaarman Avatar asked Jan 29 '13 17:01

nhaarman


2 Answers

I got the same problem. After some research, I found two hacks :

  • Add this param for your theme in the styles.xml :
    <item name="android:backgroundDimEnabled">false</item>

Bad part : it removes the black overlays behind the activity.

  • Set the z order on the top for the map object :
    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

like image 92
Aurel Avatar answered Nov 19 '22 15:11

Aurel


For DialogFragment:

getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
like image 11
IndieBoy Avatar answered Nov 19 '22 14:11

IndieBoy