Anyone know anything about how tabs are done in API 21/AppCompat Toolbar?
A lot of materials and articles what I found were old. They used old methods with ActionBar which don`t work now. At this moment I just created toolbar and have no ideas about toolbar tabs. So can anyone give examples or articles about how to make toolbar tabs with viewpager?
I created a library that could help you with this layout, but I didn't use Toolbar (I made it with RelativeLayout).
I just created a custom view that extends RelativeLayout and inside that I put all the elements (LinearLayout for the toolbar, View for the marker and a ViewPager).
Here's the CustomView class:
And here's the CustomAdapter class:
And you can find here a demo project that I created based on this solution:
https://github.com/PedroOkawa/toolbar-pager-view
Take a look at the code if you want, I hope it help you.
1 . Copy SlidingTabLayout.java from https://developer.android.com/samples/SlidingTabsColors/src/com.example.android.common/view/SlidingTabLayout.html and paste it in your package.
MainActivity.java
}
fragment_sample.xml
Pager_item.xml
There are no
Toolbar
tabs. The pattern of having tabs in the action bar was deprecated by Material Design, and when they createdToolbar
, they dropped tabs.There are no
Toolbar
tabs.You are welcome to use
PagerTabStrip
, theTabPageIndicator
from the ViewPagerIndicator library,PagerSlidingTabStrip
, etc. for yourViewPager
tabs.