Skip to main content

Mapbox Studio style

This example demonstrates how to display a custom Mapbox-hosted style in using the Mapbox Maps SDK for Android.

This example sets a default style URI specified in the layout file activity_style_mapbox_studio.xml. When the onCreate() method is called, it inflates the layout using the ActivityStyleMapboxStudioBinding and sets the content view to display the Mapbox-hosted style on the screen.

Android Examples App Available

This example code is part of the Maps SDK for Android Examples App, a working Android project available on GitHub. Android developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.

See our Run the Maps SDK for Android Examples App tutorial for step-by-step instructions.

MapboxStudioStyleActivity.kt
package com.mapbox.maps.testapp.examples

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.maps.testapp.databinding.ActivityStyleMapboxStudioBinding

/**
* Example of displaying a custom Mapbox-hosted style, the default style uri is set in layout file.
*/
class MapboxStudioStyleActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityStyleMapboxStudioBinding.inflate(layoutInflater)
setContentView(binding.root)
}
}
activity_style_mapbox_studio.xml
<?xml version="1.0" encoding="utf-8"?>
<com.mapbox.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="41.89010"
mapbox:mapbox_cameraTargetLng="12.49200"
mapbox:mapbox_cameraZoom="15"
mapbox:mapbox_styleUri="mapbox://styles/mapbox/cj3kbeqzo00022smj7akz3o1e"
tools:context=".examples.MapboxStudioStyleActivity" />
Was this example helpful?