Customize map view’s background by changing its grid properties.

Use case
A background grid defines the default color and grid for display behind a map or scene surface. Set properties on the background grid to highlight and give context to your map view or scene view.
How to use the sample
Tap the floating action button on the bottom right to open the settings UI. Tap the color next to “Color” and “Line Color” rows to change the background color and the grid’s line color respectively. Use the sliders to change the grid line width and grid size.
How it works
- Create an
ArcGISMapobject. - Display the map in a
MapView. - Apply the
backgroundGridon theMapViewusing the composable. - Update the background grid properties from the settings pane. The following
BackgroundGridproperties are updated:color: fill colorlineColor: color of background grid lineslineWidth: width (in points) of background grid linessize: size (in points) of the background grid
Relevant API
- BackgroundGrid
- Map
- MapView
Tags
background, grid, map
Sample code
/* Copyright 2026 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.changemapviewbackground.components
import android.app.Applicationimport androidx.compose.ui.graphics.Colorimport androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.viewModelScopeimport com.arcgismaps.mapping.ArcGISMapimport com.arcgismaps.mapping.Basemapimport com.arcgismaps.mapping.layers.ArcGISTiledLayerimport com.arcgismaps.mapping.view.BackgroundGridimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModelimport com.esri.arcgismaps.sample.sampleslib.components.toArcGISColorimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.flow.updateimport kotlinx.coroutines.launch
class ChangeMapViewBackgroundViewModel(app: Application) : AndroidViewModel(app) {
// A map with a single tiled layer representing world time zones, used as the basemap. val arcGISMap = ArcGISMap( basemap = Basemap(baseLayer = ArcGISTiledLayer(uri = WORLD_TIME_ZONES_URI)) )
// The background grid drawn behind the map's content. Mutating its properties // updates the MapView immediately since it's the same instance passed to MapView. val backgroundGrid = BackgroundGrid().apply { color = ChangeMapViewBackgroundUiState.defaultState.color.toArcGISColor() lineColor = ChangeMapViewBackgroundUiState.defaultState.lineColor.toArcGISColor() lineWidth = ChangeMapViewBackgroundUiState.defaultState.lineWidth size = ChangeMapViewBackgroundUiState.defaultState.size }
// Create a state flow to hold the UI state for the supporting pane controls private val _changeMapViewBackgroundUiState = MutableStateFlow(ChangeMapViewBackgroundUiState.defaultState)
// Expose the state flow as read-only for the UI val changeMapViewBackgroundUiState = _changeMapViewBackgroundUiState.asStateFlow()
// Create a message dialog view model for handling error messages val messageDialogVM = MessageDialogViewModel()
init { // Load the map and handle any errors by showing a message dialog viewModelScope.launch { arcGISMap.load().onFailure { messageDialogVM.showMessageDialog(it) } } }
/** * Updates the background grid's fill color. */ fun updateColor(color: Color) { _changeMapViewBackgroundUiState.update { currentState -> currentState.copy(color = color) } backgroundGrid.color = color.toArcGISColor() }
/** * Updates the background grid's line color. */ fun updateLineColor(color: Color) { _changeMapViewBackgroundUiState.update { currentState -> currentState.copy(lineColor = color) } backgroundGrid.lineColor = color.toArcGISColor() }
/** * Updates the background grid's line width, in device-independent pixels (DIP). */ fun updateLineWidth(lineWidth: Float) { _changeMapViewBackgroundUiState.update { currentState -> currentState.copy(lineWidth = lineWidth) } backgroundGrid.lineWidth = lineWidth }
/** * Updates the size of each grid square, in device-independent pixels (DIP). */ fun updateSize(size: Float) { _changeMapViewBackgroundUiState.update { currentState -> currentState.copy(size = size) } backgroundGrid.size = size }
companion object { /** The valid range for the grid's line width slider. */ val lineWidthRange = 0f..10f
/** The valid range for the grid's size slider. */ val sizeRange = 2f..50f
private const val WORLD_TIME_ZONES_URI = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer" }}
/** * Central UI state for the sample's controls. */data class ChangeMapViewBackgroundUiState( val color: Color, val lineColor: Color, val lineWidth: Float, val size: Float) { companion object { val defaultState = ChangeMapViewBackgroundUiState( color = Color.Black, lineColor = Color.White, lineWidth = 2f, size = 32f ) }}/* Copyright 2026 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.changemapviewbackground
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport com.esri.arcgismaps.sample.sampleslib.theme.SampleAppThemeimport com.esri.arcgismaps.sample.changemapviewbackground.screens.ChangeMapViewBackgroundScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { SampleAppTheme { Surface(color = MaterialTheme.colorScheme.background) { ChangeMapViewBackgroundScreen() } } } }}/* Copyright 2026 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.changemapviewbackground.screens
import androidx.compose.animation.animateContentSizeimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material3.HorizontalDividerimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Sliderimport androidx.compose.material3.Surfaceimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.unit.dpimport com.esri.arcgismaps.sample.changemapviewbackground.components.ChangeMapViewBackgroundUiStateimport com.esri.arcgismaps.sample.changemapviewbackground.components.ChangeMapViewBackgroundViewModelimport com.esri.arcgismaps.sample.sampleslib.components.ColorPickerPanel
/** * Supporting pane content for the sample. Lets the user configure the MapView's * background grid: its fill color, line color, line width, and grid square size. * Styled as a single grouped card under a small section label. */@Composableinternal fun ChangeMapViewBackgroundSupportingPane( adaptiveUiState: ChangeMapViewBackgroundUiState, onColorChange: (Color) -> Unit, onLineColorChange: (Color) -> Unit, onLineWidthChange: (Float) -> Unit, onSizeChange: (Float) -> Unit) { // This content is in a scrollable ColumnScope, so Composables can be added without // the Column wrapper.
Text( text = "BACKGROUND GRID", style = MaterialTheme.typography.labelMedium )
Surface( modifier = Modifier .fillMaxWidth() .animateContentSize(), shape = RoundedCornerShape(16.dp), tonalElevation = 12.dp ) { Column { ColorPickerPanel( title = "Color", color = adaptiveUiState.color, onColorChange = onColorChange, supportsOpacity = false, modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp) )
HorizontalDivider()
ColorPickerPanel( title = "Line Color", color = adaptiveUiState.lineColor, onColorChange = onLineColorChange, supportsOpacity = true, modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp) )
HorizontalDivider()
SliderRow( title = "Line Width", value = adaptiveUiState.lineWidth, valueRange = ChangeMapViewBackgroundViewModel.lineWidthRange, onValueChange = onLineWidthChange )
HorizontalDivider()
SliderRow( title = "Grid Size", value = adaptiveUiState.size, valueRange = ChangeMapViewBackgroundViewModel.sizeRange, onValueChange = onSizeChange ) } }}
/** * A titled row with a slider for adjusting a numeric value. The label and * current value sit on one line, with the slider directly beneath. */@Composableprivate fun SliderRow( title: String, value: Float, valueRange: ClosedFloatingPointRange<Float>, onValueChange: (Float) -> Unit) { Column( modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp) ) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { Text( text = title, style = MaterialTheme.typography.bodyLarge ) Text( text = value.toInt().toString(), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End ) } Slider( value = value, onValueChange = onValueChange, valueRange = valueRange ) }}/* Copyright 2026 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.changemapviewbackground.screens
import androidx.compose.animation.animateContentSizeimport androidx.compose.foundation.layout.BoxScopeimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.Scaffoldimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.res.stringResourceimport androidx.lifecycle.compose.collectAsStateWithLifecycleimport androidx.lifecycle.viewmodel.compose.viewModelimport com.arcgismaps.toolkit.geoviewcompose.MapViewimport com.esri.arcgismaps.sample.changemapviewbackground.Rimport com.esri.arcgismaps.sample.changemapviewbackground.components.ChangeMapViewBackgroundUiStateimport com.esri.arcgismaps.sample.changemapviewbackground.components.ChangeMapViewBackgroundViewModelimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogimport com.esri.arcgismaps.sample.sampleslib.components.SampleDeviceLightDarkPreviewimport com.esri.arcgismaps.sample.sampleslib.components.SamplePreviewSurfaceimport com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBarimport com.esri.arcgismaps.sample.sampleslib.components.adaptive.AdaptiveThreePane
/** * Main composable screen for the sample. * It owns the ViewModel and hoists UI state for the scaffold and the MapView. */@Composablefun ChangeMapViewBackgroundScreen( viewModel: ChangeMapViewBackgroundViewModel = viewModel()) { val changeMapViewBackgroundUiState = viewModel.changeMapViewBackgroundUiState.collectAsStateWithLifecycle().value
MainScreenScaffold( adaptiveUiState = changeMapViewBackgroundUiState, onColorChange = viewModel::updateColor, onLineColorChange = viewModel::updateLineColor, onLineWidthChange = viewModel::updateLineWidth, onSizeChange = viewModel::updateSize, mainPaneContent = { MapView( modifier = Modifier .fillMaxSize() .animateContentSize(), arcGISMap = viewModel.arcGISMap, backgroundGrid = viewModel.backgroundGrid ) } )
viewModel.messageDialogVM.apply { if (dialogStatus) { MessageDialog( title = messageTitle, description = messageDescription, onDismissRequest = ::dismissDialog ) } }}
@Composableprivate fun MainScreenScaffold( adaptiveUiState: ChangeMapViewBackgroundUiState, onColorChange: (Color) -> Unit = {}, onLineColorChange: (Color) -> Unit = {}, onLineWidthChange: (Float) -> Unit = {}, onSizeChange: (Float) -> Unit = {}, mainPaneContent: @Composable BoxScope.() -> Unit) { Scaffold( topBar = { SampleTopAppBar(title = stringResource(R.string.change_map_view_background_app_name)) }, content = { paddingValues -> AdaptiveThreePane( modifier = Modifier .fillMaxSize() .padding(paddingValues), supportingPaneTitle = "Background Settings", mainPane = { _, _ -> mainPaneContent() }, supportingPane = { _, _ -> ChangeMapViewBackgroundSupportingPane( adaptiveUiState = adaptiveUiState, onColorChange = onColorChange, onLineColorChange = onLineColorChange, onLineWidthChange = onLineWidthChange, onSizeChange = onSizeChange ) } ) } )}
@SampleDeviceLightDarkPreview@Composablefun MainScreenPreview() { SamplePreviewSurface { MainScreenScaffold( adaptiveUiState = ChangeMapViewBackgroundUiState.defaultState, mainPaneContent = {} ) }}