Fullscreen Map
This tutorial shows how to create an immersive fullscreen map experience on Android — hiding the status bar, navigation bar, and any toolbars.
Prerequisites
- Completed the Getting Started Guide
- A MapMetrics API key and style URL from the MapMetrics Portal
Fullscreen Activity
Create a map that fills the entire screen:
kotlin
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.MapMetricsMap
import org.maplibre.android.maps.Style
class FullscreenMapActivity : AppCompatActivity() {
private lateinit var mapView: MapView
private lateinit var map: MapMetricsMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Hide action bar
supportActionBar?.hide()
setContentView(R.layout.activity_fullscreen_map)
// Enable fullscreen
enableFullscreen()
mapView = findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
mapView.getMapAsync { mapMetricsMap ->
map = mapMetricsMap
map.setStyle(
Style.Builder().fromUri(
"https://gateway.mapmetrics.org/styles/YOUR_STYLE_ID?token=YOUR_API_KEY"
)
)
map.cameraPosition = CameraPosition.Builder()
.target(LatLng(48.8566, 2.3522))
.zoom(12.0)
.build()
}
}
private fun enableFullscreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Android 11+ (API 30+)
window.insetsController?.let { controller ->
controller.hide(
WindowInsets.Type.statusBars() or
WindowInsets.Type.navigationBars()
)
controller.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
// Older Android versions
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
)
}
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) enableFullscreen()
}
override fun onStart() { super.onStart(); mapView.onStart() }
override fun onResume() { super.onResume(); mapView.onResume() }
override fun onPause() { super.onPause(); mapView.onPause() }
override fun onStop() { super.onStop(); mapView.onStop() }
override fun onDestroy() { super.onDestroy(); mapView.onDestroy() }
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
}Layout XML (res/layout/activity_fullscreen_map.xml):
xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.maplibre.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>Also add to AndroidManifest.xml:
xml
<activity
android:name=".FullscreenMapActivity"
android:theme="@style/Theme.AppCompat.NoActionBar" />Fullscreen Toggle Button
Let users switch between normal and fullscreen mode:
kotlin
import android.widget.ImageButton
private var isFullscreen = false
private fun setupFullscreenToggle() {
val toggleBtn = findViewById<ImageButton>(R.id.btnToggleFullscreen)
toggleBtn.setOnClickListener {
isFullscreen = !isFullscreen
if (isFullscreen) {
enableFullscreen()
supportActionBar?.hide()
toggleBtn.setImageResource(R.drawable.ic_fullscreen_exit)
} else {
exitFullscreen()
supportActionBar?.show()
toggleBtn.setImageResource(R.drawable.ic_fullscreen)
}
}
}
private fun exitFullscreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.show(
WindowInsets.Type.statusBars() or
WindowInsets.Type.navigationBars()
)
} else {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
}
}Next Steps
- Getting Started — Basic map setup
- Fly to a Location — Camera animations
- Disable Gestures — Control map interactions
Tip: Use BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE so users can temporarily reveal system bars by swiping from the edge — they auto-hide again after a moment. This provides the best balance between immersion and accessibility.