Mapbox-gl-native: Transparent Background In Android

Created on 15 Nov 2015  路  7Comments  路  Source: mapbox/mapbox-gl-native

@incanus is working on the iOS version of this feature. Android SurfaceView should be able to provide similar support as it extends from View. Let's look into it and see if we can make it happen.

Android feature

Most helpful comment

@tobrun I ask because I want to change the default black background of MapBox, and https://github.com/mapbox/mapbox-gl-native/issues/6575 pointed to this task as the solution to that issue. Now both of those are closed and I'm wondering what the proper way to set the background color is.

All 7 comments

Main change is to select a GL surface that is argb instead of the current rgb in C++ code

This works for texture view and was always possible if I understand correctly:

ezgif com-video-to-gif 30

But doesn't seem to be working using the new SurfaceView. If you set alpha on the map view to anything less then 1 it will be completely transparent, only displaying the widgets.

@tobrun why was this closed?

this was closed as part of an issue cleanup. As @cammace pointed out you can achieve this effect with a TextureView (this is something you can activate through mapboxmapoptions or xml). What would be the use-case for this feature? I could imagine this would have been usefull in the past before we had background layers.

@tobrun I ask because I want to change the default black background of MapBox, and https://github.com/mapbox/mapbox-gl-native/issues/6575 pointed to this task as the solution to that issue. Now both of those are closed and I'm wondering what the proper way to set the background color is.

For whoever might come across this, I solved the black background problem using the following XML attributes:

<!-- Use TextureView -->
<attr name="mapbox_renderTextureMode" format="boolean"/>
<attr name="mapbox_renderTextureTranslucentSurface" format="boolean"/>
<attr name="mapbox_foregroundLoadColor" format="color"/>

This also solved another problem where I had a transition between activities with .makeSceneTransitionAnimation, the map loaded in a fragment in the second activity, and it stayed black afterwards

@snowpong Just to add to @tudormarze's answer, specifically:

In your activity_main.xml in your <com.mapbox.mapboxsdk.maps.MapView ... you can add

        mapbox:mapbox_renderTextureMode="true"
        mapbox:mapbox_renderTextureTranslucentSurface="true"
        mapbox:mapbox_foregroundLoadColor="@color/colorWhite"

where colorWhite is a color you've set in values/colors.xml.

Was this page helpful?
0 / 5 - 0 ratings