Google has just implemented a new look to their tabs in Google Play.
I know this can be done with ViewPagerIndicator, yet I wouldn't like to use another library in my application and bump the app's size by another MB or so.
I am currently using the android.support.v4.view.PagerTabStrip (like in the old Google Play), and I'm wondering if the new look can also be implemented using the android support library.
Thanks in advance.
Tabs are created using newTab() method of TabLayout class. The title and icon of Tabs are set through setText(int) and setIcon(int) methods of TabListener interface respectively. Tabs of layout are attached over TabLayout using the method addTab(Tab) method.
A TabLayout provides a way to display tabs horizontally. When used together with a ViewPager , a TabLayout can provide a familiar interface for navigating between pages in a swipe view.
The Design Support Library includes the TabLayout
widget which allows you to implement a Google Play-lie tabs:
<android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" />
and then initializing it:
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager);
For a full example see the Cheesesquare app
This is a ready-to-use library that you can find on Github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With