MapFragment gets a dark overlay when used in DialogActivity

前端 未结 5 1119
故里飘歌
故里飘歌 2020-12-24 08:39

I\'m trying to show a MapFragment of the Android Maps v2 API in an Activity with the @android:style/Theme.DeviceDefault.Light.Di

相关标签:
5条回答
  • 2020-12-24 08:50

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

    0 讨论(0)
  • 2020-12-24 08:57

    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>
    
    0 讨论(0)
  • 2020-12-24 08:59

    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

    0 讨论(0)
  • 2020-12-24 09:04

    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

    0 讨论(0)
  • 2020-12-24 09:04

    For DialogFragment:

    getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    
    0 讨论(0)
提交回复
热议问题