How to use dark mode in SupportMapFragment?
Asked Answered
S

2

8

I'm using SupportMapFragment (class="com.google.android.gms.maps.SupportMapFragment") for map in my code.

When I switch my app to dark or night mode, everything are in dark except map fragment.

Is there any way to use dark mode in SupportMapFragment?

Thanks.

I'm using light mode map

enter image description here

I want night mode map like below

enter image description here

Socialize answered 10/5, 2016 at 10:19 Comment(2)
share your code, what you done so farRadii
Did you find anything?Marillin
B
18

You can style your map using this styling api (night mode or any other style you want) https://developers.google.com/maps/documentation/android-sdk/styling

In the class where you have the GoogleMap object, you can use a style like this one: https://github.com/googlemaps/android-samples/blob/master/ApiDemos/java/app/src/main/res/raw/mapstyle_night.json

They even have a nice preview editor to create this json: https://mapstyle.withgoogle.com/

Usage

MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_night);
GoogleMap mMap; // assigned in onMapReady()
mMap.setMapStyle(style);
Boren answered 30/9, 2016 at 22:22 Comment(2)
Unfortunately this still makes unloaded tiles white - which causes extremely unpleasant white flashes when the fragment loads.Sydelle
@Sydelle Did you ever find a solution to the white tile problem?Horripilate
E
-1

you need to add a View over the map with dark-transparent background:

 <RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/myActivity_mapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"/>

    <View
        android:id="@+id/myActivity_mapFragmentDark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#55000000"/>

</RelativeLayout>

so you can show/hide this view to dim the map:

mapFragmentDark.setVisibility(View.VISIBLE);

or

mapFragmentDark.setVisibility(View.GONE);
Externalize answered 10/5, 2016 at 10:27 Comment(2)
Thanks for giving me other option to dark a map. but I want to use dark map. I have attached screen-shots of map that I want.Socialize
AFAIK android-map doesn't support this feature currently. The only way is to dim it with the code below.Externalize

© 2022 - 2024 — McMap. All rights reserved.