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

杀马特。学长 韩版系。学妹 提交于 2019-12-08 05:20:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!