TabLayout tab selection

前端 未结 25 1460
情深已故
情深已故 2020-11-29 17:15

How should I select a tab in TabLayout programmatically?

 TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
 tabLayout.setupWithViewPager(viewPager         


        
相关标签:
25条回答
  • 2020-11-29 17:48

    If you have trouble understanding, this code can help you

    private void MyTabLayout(){
        TabLayout.Tab myTab = myTabLayout.newTab(); // create a new tab
        myTabLayout.addTab(myTab); // add my new tab to myTabLayout
        myTab.setText("new tab"); 
        myTab.select(); // select the new tab
    }
    

    You can also add this to your code:

    myTabLayout.setTabTextColors(getColor(R.color.colorNormalTab),getColor(R.color.colorSelectedTab));
    
    0 讨论(0)
提交回复
热议问题