![]() Int selectedTabPosition = tabLayout.getSelectedTabPosition() // get the position for the current selected tabħ. TabLayout tabLayout = (TabLayout) findViewById(R.id.simpleTabLayout) // get the reference of TabLayout It returns -1 if there isn’t a selected tab.īelow we get the current selected tab position. This method returns an int type value for the position of the selected tab. getSelectedTabPosition(): This method is used to get the position of the current selected tab. TabLayout.addTab(firstTab,2,true) // add the tab at specified position in the TabLayout and makes it selectableĦ. True value is used to make the tab selectable.īelow we firstly create a tab and then add it in the TabLayout at a specific position and we also set true value to make the tab selectable. The tab will be inserted at the defined position and a Boolean value used to set the state of the tab. By using this method we add the tab which we created using newTab() method in the TabLayout. addTab(Tab tab, int position, boolean setSelected): This method is used to add a tab at a specific position and set the state of the tab. TabLayout.addTab(firstTab,2) // add the tab in the TabLayout at specific positionĥ. If it is the first tab to be added then it will become the selected tab.īelow we firstly create a new tab and then add it in the TabLayout at a specific position. ![]() The tab will be inserted at the given position. addTab(Tab tab, int position): This method is used to add a tab in the TabLayout and set the state for the tab. TabLayout.addTab(firstTab,true) // add the tab in the TabLayout and makes it selectableĤ. In this method we also set the state of the tab whether it is selected or not.īelow we firstly create a new tab and then add it in the TabLayout and set the true value for setSelected parameter that makes it selectable. addTab(Tab tab, boolean setSelected):This method is used to add a tab in the TabLayout and set the state for the tab. TabLayout.addTab(firstTab) // add the tab to the TabLayoutģ. TabLayout.Tab firstTab = tabLayout.newTab() // Create a new Tab names "First Tab" The tab will be added at the end of the list and If it is the first tab to be added then it will become the selected tab.īelow we firstly create a new tab and then add it in the TabLayout. addTab(Tab tab): This method is used to add a tab in the TabLayout. ![]() TabLayout.Tab firstTab = tabLayout.newTab() // Create a new Tab namesįtText("First Tab") // set the Text for the first TabįtIcon(R.drawable.ic_launcher) // set an icon for the first tabĢ. Let’s we discuss some important methods of TabLayout that may be called in order to manage the TabLayout.ġ. newTab(): This method is used to create and return a new TabLayout.Tab.īelow we create a new tab and set the text and icon for the tab. ![]() 5 Example 2 of TabLayout Using ViewPager:. ![]()
0 Comments
Leave a Reply. |