Before that I have been using PagerSlidingTabStrip, it's really simple to use, But most of the time,I want to custom each tab or more things ,so I make this library with my thought, If you like, I hope you can give me more suggestion,Of course, I am very grateful to the PagerSlidingTabStrip author provided such a good code.
Add dependencies in build.gradle.
dependencies {
compile 'com.whl.handytabbar:library:1.0.4'
}
Add the HandyTabBar to your layout:
<com.whl.handytabbar.HandyTabBar
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="@+id/tab_bar"
android:background="@color/colorPrimary"
/>
In your java code with simple(Most of time I suggest you use customization,it's very flexible.):
mTabBar= (HandyTabBar) findViewById(R.id.tab_bar);
mTabBar.attachToViewPager(mViewPager);
When you use, I think you want more time to define your own, therefore, provided here
- TabBarStyle(whole HandyTabBar style):
TabBarStyle tabBarStyle=new TabBarStyle.Builder(this)
.setDrawIndicator(TabBarStyle.INDICATOR_LINE)
.setDrawLine(TabBarStyle.TOPLINE)
.setDrawDivider(drawDivider)
.setIndicatorHeight()
setDividerColor()
...
.build();
mTabBar.attachToViewPager(mViewPager,mTabBarStyle);
- TabLayout(Single Tab should be like):
(your need to extend BaseTabLayout,like this SimpleTabLayout CustomTabLayout in sample project)
mTabBar.attachToViewPager(mViewPager,customTabLayout);
- Tips:
HandyTabBar don't provided about animation method(maybe later), but if you want to use animation, very simple, need only in onTabState () method to implements anything you want in the animation, I strongly recommend to use AndroidViewAnimations,just like this
@Override
public void onTabState(View v, boolean isSelected,int position) {
ImageView imageView= (ImageView) v.findViewById(R.id.yourViewID);
if (isSelected){
YoYo.with(Techniques.Tada)
.duration(700)
.playOn(imageView);
}else {
...
}
}
or look this CustomTabLayout;
##Contact me
I love open source project, if you have a better idea on this project or way, please let me know, thanks:)