Pagorn Petchara Pagorn Petchara - 3 months ago 11
Android Question

Can I click tab in TabLayout by coding or method?

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

Answer

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!