Skip to main content

UI settings

A newer version of the Maps SDK is available
This page uses v9.7.1 of the Mapbox Maps SDK. A newer version of the SDK is available. Learn about the latest version, v11.8.0, in the Maps SDK documentation.

The Mapbox Maps SDK for Android gives developers the ability to adjust certain elements of the map's user interface (UI). Once a MapboxMap has been correctly set up, get its UiSettings object.


mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {

UiSettings uiSettings = mapboxMap.getUiSettings();


}
});

Make changes to gesture recognition, the compass, the Mapbox logo, and attribution after you have the UiSettings object. Changes made to UiSettings are immediately reflected on the map.

You can also configure the UI settings with the Maps SDK's XML attributes instead of the UiSettings class' methods.

All the UI settings also have "get" methods that allow you to see the current settings (for example, if the compass is enabled, what the logo's margins are, or what the custom compass image is).


mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {

UiSettings uiSettings = mapboxMap.getUiSettings();

uiSettings.areAllGesturesEnabled();

}
});

Gestures

The Mapbox Maps SDK for Android uses the Mapbox Gestures for Android library to detect gestures.

Adjust or completely disable zoom, tilt, scroll, rotate, quick zoom, and double tap gesture recognition. Disabling map gestures doesn't affect whether you can change the camera position programmatically.

For example, here's how you would disable the ability to increase the zoom level by double tapping on the map:


mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {

UiSettings uiSettings = mapboxMap.getUiSettings();

uiSettings.setDoubleTapGesturesEnabled(false);

}
});

See the map camera position documentation for more information about how gestures can affect camera position.

Compass

The Maps SDK contains a compass image, which appears on the map when the map is rotated in any direction. The compass doesn't represent the physical device's relation to the magnetic north pole. The compass image rotates based on the on-screen map rotation.

When the user clicks on the compass image, the camera animates back to the default north orientation (bearing of 0) and the compass image fades away shortly afterwards.

By default, the compass appears in the upper right hand corner of the MapView, but its margins can be adjusted. A custom drawable image can be passed to the Maps SDK to replace the default image.

Another option is to completely disable the compass:


mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {

UiSettings uiSettings = mapboxMap.getUiSettings();

uiSettings.setCompassEnabled(false);

}
});

Logo and attribution

Read Mapbox's attribution policy for information on displaying the Mapbox wordmark logo and attribution.

The logo's properties such as margins and gravity can be adjusted with XML or the UiSettings object. The attribution i icon's properties such as tint, margins, and gravity can also be adjusted with XML or the UiSettings object.

EXAMPLE
Attribution icon color

See how to customize the attribution i icon's color to match a map style or stand out from the style color.