Customize info panel background and additional properties using Navigation View
NOTE
This example is a part of the Navigation SDK Examples. You can find the values for all referenced resources in the res
directory. For example, see res/values/strings.xml
for R.string.*
references used in this example.
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:app="http://schemas.android.com/apk/res-auto"> <com.mapbox.navigation.dropin.NavigationViewandroid:id="@+id/navigationView"android:layout_width="match_parent"android:layout_height="match_parent"app:accessToken="@string/mapbox_access_token" /> <com.google.android.material.floatingactionbutton.FloatingActionButtonandroid:id="@+id/toggleInfoPanelStyles"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginEnd="16dp"android:layout_marginBottom="120dp"android:src="@drawable/mapbox_ic_customize"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintBottom_toBottomOf="parent"tools:ignore="ContentDescription"/></androidx.constraintlayout.widget.ConstraintLayout>
package com.mapbox.navigation.examples.dropinui.styling import android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport com.mapbox.navigation.dropin.ViewStyleCustomizationimport com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelBackgroundimport com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelMarginEndimport com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelMarginStartimport com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelPeekHeightimport com.mapbox.navigation.examples.Rimport com.mapbox.navigation.examples.databinding.MapboxActivityCustomizeInfopanelOptionsBinding /*** The example demonstrates how to use [ViewStyleCustomization] to customize the peek height,* margins and background for the default info panel supplied by Drop-In UI.** Before running the example make sure you have put your access_token in the correct place* inside [app-preview/src/main/res/values/mapbox_access_token.xml]. If not present then add* this file at the location mentioned above and add the following content to it** <?xml version="1.0" encoding="utf-8"?>* <resources xmlns:tools="http://schemas.android.com/tools">* <string name="mapbox_access_token"><PUT_YOUR_ACCESS_TOKEN_HERE></string>* </resources>** The example uses replay location engine to facilitate navigation without physically moving.** How to use the example:* - Start the example* - Grant the location permissions if not already granted* - Press on the floating button in the bottom right to apply custom styles*/class CustomInfoPanelAttributesActivity : AppCompatActivity() { private lateinit var binding: MapboxActivityCustomizeInfopanelOptionsBindingprivate var toggleInfoPanelStyles = false override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)binding = MapboxActivityCustomizeInfopanelOptionsBinding.inflate(layoutInflater)setContentView(binding.root) binding.navigationView.api.routeReplayEnabled(true) binding.toggleInfoPanelStyles.setOnClickListener {customizeInfoPanelStyles(toggleInfoPanelStyles)toggleInfoPanelStyles = !toggleInfoPanelStyles}} private fun customizeInfoPanelStyles(enabled: Boolean) {binding.navigationView.customizeViewStyles {if (enabled) {infoPanelBackground = defaultInfoPanelBackground()infoPanelPeekHeight = defaultInfoPanelPeekHeight(this@CustomInfoPanelAttributesActivity)infoPanelMarginEnd = defaultInfoPanelMarginEnd()infoPanelMarginStart = defaultInfoPanelMarginStart()} else {infoPanelBackground = R.drawable.mapbox_bg_custom_info_panelinfoPanelPeekHeight = this@CustomInfoPanelAttributesActivity.resources.getDimensionPixelSize(R.dimen.mapbox_custom_infopanel_peekheight)infoPanelMarginEnd = this@CustomInfoPanelAttributesActivity.resources.getDimensionPixelSize(R.dimen.mapbox_custom_infopanel_marginEnd)infoPanelMarginStart = this@CustomInfoPanelAttributesActivity.resources.getDimensionPixelSize(R.dimen.mapbox_custom_infopanel_marginStart)}}}}
Was this example helpful?