EasyTabs库
EasyTabs的Android库,可帮助创建和轻松定制material design标签。
使用方式:
repositories { maven { url "https://jitpack.io" } }
compile 'com.android.support:design:23.3.0'
compile 'com.github.gilgoldzweig:EasyTabs:f434d9f635'
不建议这么做,建议将Tabs库以Modual形式导入项目中,这样可定制化动画,而且减少不必要的代码。因为库中动画效果比较多。
例如:
使用:
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabs"
android:background="@color/colorPrimary"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager"
android:layout_below="@+id/tabs"/>
因为是针对TabLayout+ViewPager组合的滑动动画库
Java文件
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Typeface selected;
selected = Typeface.createFromAsset(getAssets(), "fonts/bubble.ttf");
colors = new EasyTabsColors();
builder = new EasyTabsBuilder(this, tabs, pager)
.addTabs(false,
new TabItem(new frag1(), "number 1"),
new TabItem(new frag2(), "number 2"),
new TabItem(new frag3(), "number 3"),
new TabItem(new frag4(), "number 4"),
new TabItem(new frag1(), "number 1"),
new TabItem(new frag2(), "number 2"),
new TabItem(new frag3(), "number 3"),
new TabItem(new frag4(), "number 4"),
new TabItem(new frag1(), "number 5")
)
.setBackgroundColor(colors.RoyalBlue)
.setIndicatorColor(colors.White)
.setTextColors(colors.White, colors.DarkSlateBlue)
.addIcons(R.drawable.ic_person_white_36dp,
R.drawable.ic_photo_camera_white_36dp,
R.drawable.ic_favorite_white_36dp,
R.drawable.ic_help_white_36dp,
R.drawable.ic_person_white_36dp)
.setTransformation(true, new EasyRotateDownTransformer())
.setTabLayoutScrolable(false)
.setTypeface(selected)
.setToRTL(false)
.withIconFading(true);
}
选择字体
selected = Typeface.createFromAsset(getAssets(), “fonts/bubble.ttf”);
设置字体
setTypeface(selected)
设置背景
setBackgroundColor
设置下划线颜色
setIndicatorColor
设置字体颜色
setTextColors
添加图标
addIcons
设置滑动动画
setTransformation
动画种类
很多,选择性使用。
效果:
AccordionTransformer
BackgroundToForegroundTransformer
CubeInTransformer
旋转90度退出
CubeOutTransformer
旋转90度进入
DepthPageTransformer
FlipHorizontalTransformer
中心水平翻转
FlipVerticalTransformer
中心垂直翻转
ForegroundToBackgroundTransformer
缩放退出
RotateDownTransformer
RotateUpTransformer
顶部旋转
ScaleInOutTransformer
StackTransformer
TabletTransformer
ZoomInTransformer
ZoomOutSlideTransformer
ZoomOutTranformer
嗯动画很丰富,值得参考!
github地址: