I am working on an app where I want to add tabs so that can be added using PagerTabStrip and TabLayout with ViewPager.
It looks same to me with no difference but I guess there is some difference between them so they are two classes for this. So what is the main difference between them?
Just comparing the visuals...
TabLayoutis a material concept that replaced the deprecated ActionBar tabs in Android 5.0.It extends
HorizontalScrollView, so you can keep adding tabs horizontally which can include text, icons, or custom views and scroll through them linearly without paging.TabLayoutprovides thesetupWithViewPager(ViewPager viewPager)method to attach to aViewPagerinstead of being part of theViewPagerlike thePagerTabStrip.A
PagerTabStripis more of an indictor for the current page of a ViewPager, and "it is intended to be used as a child view of a ViewPager widget". The scrolling for it does not act like theTabLayoutsince each tab is part of the page instead of individually horizontally scrollable.In summary, the differences are (apart from visuals).
TabLayoutis part of the Activity/Fragment, outside of theViewPager, and you instead attach it to one. It scrolls separately from the pages.PagerTabStripis a child element of theViewPager. The tabs scroll with the page.