Currently, when I open the app, the left most button is initially clicked. How do I change it so that the middle button is initially clicked when the app is run.
-Thanks
Tow way to define default fragment :
1st : Set the selected index setSelectedItemId
bottomNavigation.setSelectedItemId(R.id.item_id);
2nd : Also you can create PushFragment
method like below :
public void PushFragment(Fragment fragment){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.nav_Frame, fragment).addToBackStack( "HomeFragment" ).commit();
}
And in onCreate()
method declare PushFragment()
with your default fragment id see below code :
PushFragment(new HomeFragment());
How you are loading bottom navigation bar items dynamically or static???
static means use like this:
bottomNavigationView.setSelectedItemId(R.id.your_middle_item_id);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.