• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Customize Floating Buttons

Customize styling of floating buttons

This example shows:

  • How to customize the styling of Navigation floating buttons

    • navigationViewReCentreInfoColor
    • navigationViewReCentreBackgroundDrawable
    • navViewSoundColor
    • navViewSoundBackgroundColor
    • navViewPauseColor
    • navViewPauseBackgroundColor
    • navViewRestartColor
    • navViewRestartBackgroundColor
    • navigationCurrentSpeedBackgroundColor
    • navigationCurrentSpeedTextColor
    • navigationCurrentSpeedUnitTextColor
  • How to config custom navigation style using NavLauncherConfig.Builder

docs-image

For all code examples, refer to Navigation Code Examples

activity_custom_floating_buttons_style.xml view source

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical"
6 android:padding="10dp">
7
8 <LinearLayout
9 android:layout_width="wrap_content"
10 android:orientation="vertical"
11 android:layout_height="wrap_content">
12 <Button
13 android:id="@+id/fetchRoute"
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:textSize="12sp"
17 android:text="@string/fetch_route"/>
18

themes.xml view source

1<style name="Theme.CustomNavFloatingButtons" parent="NavigationViewLight">
2 <!-- You can customize your navigation style here-->
3 <item name="navigationViewReCentreInfoColor">#FFA90403</item>
4 <item name="navigationViewReCentreBackgroundDrawable">@drawable/recenter_btn_background</item>
5 <item name="navViewSoundColor">#FFA90403</item>
6 <item name="navViewSoundBackgroundColor">#FF6E7ACA</item>
7 <item name="navViewPauseColor">#FFFFC0A8</item>
8 <item name="navViewPauseBackgroundColor">@color/white</item>
9 <item name="navViewRestartColor">#FFFFC0A8</item>
10 <item name="navViewRestartBackgroundColor">@color/white</item>
11 <item name="navigationCurrentSpeedBackgroundColor">#FF6E7ACA</item>
12 <item name="navigationCurrentSpeedTextColor">@color/black</item>
13 <item name="navigationCurrentSpeedUnitTextColor">#FF9E10FF</item>
14</style>
15
16<style name="Theme.CustomNavFloatingButtonsDark" parent="NavigationViewDark">
17 <!-- You can customize your navigation style here-->
18 <item name="navigationViewReCentreInfoColor">#FFA90403</item>

CustomFloatingButtonsStyleActivity view source

1package ai.nextbillion.navigation.demo.activity;
2
3import android.os.Bundle;
4import android.view.View;
5import android.widget.Button;
6import android.widget.ProgressBar;
7import android.widget.TextView;
8
9import ai.nextbillion.kits.directions.models.DirectionsResponse;
10import ai.nextbillion.kits.directions.models.DirectionsRoute;
11import ai.nextbillion.kits.geojson.Point;
12import ai.nextbillion.maps.location.modes.RenderMode;
13import ai.nextbillion.navigation.demo.R;
14import ai.nextbillion.navigation.ui.NBNavigation;
15import ai.nextbillion.navigation.ui.NavLauncherConfig;
16import ai.nextbillion.navigation.ui.NavigationLauncher;
17import androidx.annotation.NonNull;
18import androidx.appcompat.app.AppCompatActivity;

Code Highlights

This code example shows how to customize the navigation view floating buttons via themes.xml configuration file.

The key part of the code example is the definition of the theme styles Theme.CustomNavFloatingButtons based on NavigationViewLight and Theme.CustomNavFloatingButtonsDark based on NavigationViewDark These styles are used to customize the appearance of the floating buttons in the navigation view.

The customized styles are applied to the navigation view by setting the lightThemeResId and darkThemeResId to NavLauncherConfig before start navigation

Code summary

In this code example:

  • configBuilder.lightThemeResId(R.style.Theme_CustomNavFloatingButtons) sets the light theme for the navigation UI, using the Theme_CustomNavFloatingButtons style defined earlier. This style determines the appearance of the floating buttons in the navigation view.

  • configBuilder.darkThemeResId(R.style.Theme_CustomNavFloatingButtonsDark) sets the dark theme for the navigation UI, using the Theme_CustomNavFloatingButtonsDark style defined earlier. This style is applied when the device's dark mode is enabled.

  • the action after clicking the fetch route button shows how to fetch a route using NBNavigation.fetchRoute(origin, destination, new Callback<DirectionsResponse>() { ... }); The origin and destination points are passed as parameters, along with a callback to handle the response asynchronously.

Have Questions ?