TabLayout selected Tab icon is not selected on start up

前端 未结 6 437
小鲜肉
小鲜肉 2021-01-17 14:14

I\'m using a TabLayout for Tabbed navigation in my app. I have a really weird issue with it, I have created 4 tabs using this code:

private int[         


        
6条回答
  •  走了就别回头了
    2021-01-17 15:03

    The correct answer for tab selection in TabLayout would be:

    TabLayout.Tab currentTab = mTabs.getTabAt(selectedTab);
    if (currentTab != null) {
        View customView = currentTab.getCustomView();
        if (customView != null) {
            customView.setSelected(true);
        }
        currentTab.select();
    }
    

    where currentTab.select() will move the indicator to the selected tab, when customView.setSelected() will make all the items in the custom view set their selected states from the selectors look selected.

提交回复
热议问题