Launch Custom NavigationView
A complete turn-by-turn experience using custom NavigationView
This example shows:
-
How to fetch a route using
RouteFetcher.getRoute
withRouteRequestParams.Builder
-
How to initialize a
NavigationView
and bind it to the activity lifecycle -
How to config
NavEngineConfig.Builder
andNavViewConfig.Builder
in theonNavigationReady()
callback -
How to start navigation using
navigationView.startNavigation
For all code examples, refer to Navigation Code Examples
activity_custom_navigation.xml view source
activity_navigation_view.xml view source
CustomNavigationActivity view source
NavigationViewActivity view source
Code summary
This code example shows how to customize the NavigationView and launch it
-
The code provided an AppCompatActivity called NavigationViewActivity that demonstrates the usage of the
NavigationView
class for navigation purposes. -
The
onCreate()
method is overridden to set up the activity layout and initialize the NavigationView-
StatusBarUtils.transparentStatusBar(this,this):
sets the status bar to be transparent -
StatusBarUtils.setLightMode/DarkMode(this);
set the status bar text and icons to be displayed in light/dark color, making them visible against the light/dark background.
-
-
The requestPermissions() method is called to request location permissions.
-
The onRequestPermissionsResult() method handles the result of the permission request.
-
navigationView.initialize(this)
was called after the location permission was granted. The onNavigationReady() method is implemented from theOnNavigationReadyCallback
interface, which is called when the navigation is ready to start.
-
-
The configRoute() method is used to configure the navigation route by extracting route information from the intent extras.
-
Various configuration options are set using
NavViewConfig.Builder
, such as enabling route simulation, showing a speedometer, setting the location layer render mode, and providing the navigation configuration. -
The
startNavigation()
method is called on the NavigationView instance to begin the navigation.
-
-
Lifecycle methods (onStart(), onResume(), onLowMemory(), etc.) are overridden to forward the calls to the NavigationView instance.
-
The onBackPressed() method is overridden to handle the back button press and allows the NavigationView to handle it if necessary.
-
Methods for handling instance state, permissions granted/denied, navigation callbacks, and window insets are implemented.
-
The activity's lifecycle methods (onSaveInstanceState(), onRestoreInstanceState(), etc.) are overridden to propagate the corresponding calls to the NavigationView.
-
the activity is destroyed by calling onDestroy() on the NavigationView.
-