Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bottom Navigation View : Change the default highlighted Tab when the app launches

My Navigation View

As shown above, I have this button navigation view, when ever I launch my application, in default my "Catagories" tab gets highlighted, but I want to get my "Home" tab get highlighted when i launch my application, can anyone help me get out of it?

like image 389
TheSwiftGuy77 Avatar asked Dec 07 '25 08:12

TheSwiftGuy77


2 Answers

try this use setSelectedItemId() method of your BottomNavigationView like this

BottomNavigationView bottomNavigationView;
bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigationView);
bottomNavigationView.setSelectedItemId(R.id.home_menu);

or use viewPager.setCurrentItem(); of your view pager like this

viewPager.setCurrentItem(2);
like image 148
AskNilesh Avatar answered Dec 09 '25 21:12

AskNilesh


You can specify a start destination in the res/navigation/mobile_navigation.xml.

Change the app:startDestination="@+id/navigation_home" row:

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mobile_navigation"
    app:startDestination="@+id/navigation_home">

    <fragment
        android:id="@+id/navigation_home"
        android:name="com.github.bottomchan.ui.home.HomeFragment"
        android:label="@string/title_home"
        tools:layout="@layout/fragment_home" />

    <fragment
        android:id="@+id/navigation_dashboard"
        android:name="com.github.bottomchan.ui.dashboard.DashboardFragment"
        android:label="@string/title_dashboard"
        tools:layout="@layout/fragment_dashboard" />
</navigation>

like image 32
James Bond Avatar answered Dec 09 '25 21:12

James Bond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!