Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dark mode in SupportMapFragment?

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

like image 427
Tejas Patel Avatar asked Dec 07 '22 22:12

Tejas Patel


1 Answers

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);
like image 143
Afzal N Avatar answered Dec 10 '22 10:12

Afzal N