Reputation: 612
I have problem when Toolbar collapse. The CoordinatorLayout is not collapse. This problem is cause by I call keyboard. but when I click Tab in TabLayout the CoordinatorLayout is working correct again.
That is why I want to click tab in TabLayout by coding or method.
UPDATE: This question is relate with this LINK
Upvotes: 3
Views: 2080
Reputation: 1048
I have to find the method for myself just to achieve this:
TabLayout.Tab newTab = tabLayout.getTabAt(int indexnumber);
newTab.select();
Hope that helps you.
PS. This is using the TabLayout class on the Android design library
Upvotes: 4
Reputation: 2596
You might have to elaborate on how you're using a tab layout, but if you have your TabLayout setup with a ViewPager like this:
mTabLayout.setupWithViewPager(mViewPager);
then you can call .setCurrentItem(int) on the ViewPager like this:
mViewPager.setCurrentItem(1);
to programatically set the page number. When you have your TabLayout setup with a Viewpager as shown, this will also change your tab in the TabLayout. Here I've set it to 1. Hope this helps!
Upvotes: 2