问题
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?
回答1:
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);
回答2:
/***Just try to use below code snipet***/
viewPager.setCurrentItem(2);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
home_icon.setImageDrawable(getResources().getDrawable(R.drawable.home_icon_selected_state, getApplicationContext().getTheme()));
}
else
{
home_icon.setImageDrawable(getResources().getDrawable(R.drawable.home_icon_selected_state));
}
来源:https://stackoverflow.com/questions/46048657/bottom-navigation-view-change-the-default-highlighted-tab-when-the-app-launche