step1:在module.gradle中添加

[java] view plaincopy
  1. dependencies{
  2. compile 'com.android.support:support-v4:23.1.1'
  3. compile 'com.nineoldandroids:library:2.4.0'
  4. compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
  5. compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.5.0@aar'
  6. }
  7. After v2.0.0
  8. dependencies{
  9. compile 'com.android.support:support-v4:23.1.1'
  10. compile 'com.nineoldandroids:library:2.4.0'
  11. compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.0.0@aar'
  12. }

step 2:建立TabEntity这里是tab的标题、选中的图标、未选中的图标

[java] view plaincopy
  1. package com.example.maoyh.myapplication.app.entity;
  2. import com.flyco.tablayout.listener.CustomTabEntity;
  3. public class TabEntity implements CustomTabEntity {
  4. public String title;
  5. public int selectedIcon;
  6. public int unSelectedIcon;
  7. public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
  8. this.title = title;
  9. this.selectedIcon = selectedIcon;
  10. this.unSelectedIcon = unSelectedIcon;
  11. }
  12. @Override
  13. public String getTabTitle() {
  14. return title;
  15. }
  16. @Override
  17. public int getTabSelectedIcon() {
  18. return selectedIcon;
  19. }
  20. @Override
  21. public int getTabUnselectedIcon() {
  22. return unSelectedIcon;
  23. }
  24. }

step 3:建立要关联的fragment

[java] view plaincopy
  1. package com.example.maoyh.myapplication.app.fragment;
  2. import android.os.Bundle;
  3. import android.support.v4.app.Fragment;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.widget.TextView;
  8. import com.example.maoyh.myapplication.app.R;
  9. /**
  10. * Created by MAOYH on 2016/3/2.
  11. */
  12. public class SimpleCardFragment extends Fragment {
  13. private String mTitle;
  14. public static SimpleCardFragment getInstance(String title) {
  15. SimpleCardFragment sf = new SimpleCardFragment();
  16. sf.mTitle = title;
  17. return sf;
  18. }
  19. @Override
  20. public void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. }
  23. @Override
  24. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  25. View v = inflater.inflate(R.layout.layout_fragment, null);
  26. TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
  27. card_title_tv.setText(mTitle);
  28. return v;
  29. }
  30. }

step 4:设置activity的layout

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. xmlns:tl="http://schemas.android.com/apk/res-auto"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
  10. <FrameLayout
  11. android:id="@+id/fl_change"
  12. android:layout_width="match_parent"
  13. android:layout_height="400dp">
  14. </FrameLayout>
  15. <com.flyco.tablayout.CommonTabLayout
  16. android:layout_alignBottom="@+id/fl_change"
  17. android:id="@+id/tl"
  18. android:layout_width="match_parent"
  19. android:layout_height="48dp"
  20. android:background="#ffffff"
  21. android:layout_alignParentBottom="true"
  22. tl:tl_iconGravity="LEFT"
  23. tl:tl_iconHeight="18dp"
  24. tl:tl_iconMargin="5dp"
  25. tl:tl_iconWidth="18dp"
  26. tl:tl_indicator_bounce_enable="true"
  27. tl:tl_indicator_color="#2C97DE"
  28. tl:tl_indicator_gravity="BOTTOM"
  29. tl:tl_indicator_height="0dp"
  30. tl:tl_textSelectColor="#2C97DE"
  31. tl:tl_textUnselectColor="#66000000"
  32. tl:tl_textsize="15sp"
  33. tl:tl_underline_color="#DDDDDD"
  34. tl:tl_underline_gravity="TOP"
  35. tl:tl_underline_height="1dp"/>
  36. </RelativeLayout>

step 5:fragment的layout

step 6:编码activity

[java] view plaincopy
  1. package com.example.maoyh.myapplication.app.activity;
  2. import android.os.Bundle;
  3. import android.support.v4.app.Fragment;
  4. import android.support.v7.app.AppCompatActivity;
  5. import com.example.maoyh.myapplication.app.R;
  6. import com.example.maoyh.myapplication.app.entity.TabEntity;
  7. import com.example.maoyh.myapplication.app.fragment.SimpleCardFragment;
  8. import com.flyco.tablayout.CommonTabLayout;
  9. import com.flyco.tablayout.listener.CustomTabEntity;
  10. import java.util.ArrayList;
  11. public class MainActivity extends AppCompatActivity {
  12. private ArrayList<Fragment> mFragments = new ArrayList<>();
  13. private CommonTabLayout mTabLayout;
  14. private String[] mTitles = {"首页", "消息", "联系人", "我的"};
  15. private int[] mIconUnselectIds = {
  16. R.mipmap.tab_home_unselect, R.mipmap.tab_speech_unselect,
  17. R.mipmap.tab_contact_unselect, R.mipmap.tab_more_unselect};
  18. private int[] mIconSelectIds = {
  19. R.mipmap.tab_home_select, R.mipmap.tab_speech_select,
  20. R.mipmap.tab_contact_select, R.mipmap.tab_more_select};
  21. //tab的标题、选中图标、未选中图标
  22. private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_main);
  27. initData();
  28. initView();
  29. //给tab设置数据和关联的fragment
  30. mTabLayout.setTabData(mTabEntities, this, R.id.fl_change, mFragments);
  31. //设置红点
  32. mTabLayout.showDot(1);
  33. }
  34. private void initView() {
  35. mTabLayout = (CommonTabLayout) findViewById(R.id.tl);
  36. }
  37. private void initData() {
  38. for (String title : mTitles) {
  39. mFragments.add(SimpleCardFragment.getInstance( title));
  40. }
  41. //设置tab的标题、选中图标、未选中图标
  42. for (int i = 0; i < mTitles.length; i++) {
  43. mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
  44. }
  45. }
  46. }

FlycoTabLayout使用相关推荐

  1. 《Android 开源库》 FlycoTabLayout 从头到脚

    简介 FlycoTabLayout,是一个比Google原生TabLayout 功能更强大的TabLayout库.目前有3种TabLayout: SlidingTabLayout CommonTabL ...

  2. FlycoTabLayout第三方控件设置选中放大

    github地址:https://github.com/H07000223/FlycoTabLayout <com.flyco.tablayout.SlidingTabLayoutandroid ...

  3. FlycoTabLayout - SegmentTabLayout的使用

    一:导入依赖: implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' 二:布局文件: 布局文件:SegmentTabLay ...

  4. 最新最全的 Android 开源项目合集(一)

    原文链接:https://github.com/opendigg/awesome-github-android-ui 抽屉菜单 MaterialDrawer ★7337 - 安卓抽屉效果实现方案 Si ...

  5. 15类Android通用流行框架

    15类Android通用流行框架 Android流行框架 缓存 DiskLruCache Java实现基于LRU的磁盘缓存 图片加载 Android Universal Image Loader 一个 ...

  6. Android开发常用开源框架3

    AndroidImageSlider Android-ConvenientBanner DecentBanner AndroidSwipeLayout 为对象提供滑动功能,例如滑动删除. AirMap ...

  7. Android 开源库和项目 2

    1.带尾巴的RecyclerViewPager 特点:1.像viewPager一样滑动一次就滑动一页 2.像画廊gallery一样,滑动一次可以滑动很多页 3.竖向滑动 4.支持点击事件,没有错乱   ...

  8. Android常用开源框架

    快速索引 框架名称 上榜关键字 1.Retrofit 网络 2.okhttp 网络 3.Butter Knife 代码模板 4.MPAndroidChart 图表 5.glide 图片 6.leakc ...

  9. tablayout支持改变选中文字大小,支持左右滑动,支持viewpager,支持三角可移动指示器...

    TabLayout  [简书地址] (https://www.jianshu.com/p/2c3f868266e8) 基于大神的FlycoTabLayout [传送地址和基本用法](https://g ...

最新文章

  1. mysql 数据库连接字符串,mysql基本语句和连接字符串_数据库技巧
  2. CMake编译Widget UI Qt程序
  3. PyQt5 Introduction and components
  4. Java 重定位 —— redirect:
  5. 阿里云原生多模数据库Lindorm联合东软云科技,赋能车联网数字化运营运维创新升级
  6. [POJ1338]Ugly Numbers
  7. 在ThoughtWorks工作12年的技术主管,所总结的12条技术人经验
  8. 【设计模式】五、单例模式(独一无二的对象)
  9. 链表 队列 基本概念 为什么使用二叉查找树 抽象数据类型
  10. livechart 只显示 y 值_【科研工具51】谷歌,谷歌学术,Scihub有效网址检索软件——Y学术...
  11. (转)linux下vi编辑器编写C语言的配置
  12. oracle导出自增设置,oracle008:oracle自增,自适应,数据闪回,导入导出
  13. 《Tomcat权威指南》读书笔记
  14. Centos7搭建pptp一键安装脚本
  15. 捡到iphone6怎么解锁_赛博朋克2077前期手枪用哪个好?2077节制结局及银杯节制解锁条件...
  16. C++开源日志库选择
  17. 仓库管理软件中的账套是什么意思
  18. MySQL 5.7(windows 64位)下载安装
  19. 微信小程序tabbar消失_微信小程序tabBar底部导航 不显示问题解析
  20. MATLAB中Imcrop函数的用法

热门文章

  1. 无重复最长子串python_leetCode 无重复字符的最长子串 python(Longest Substring Without Repeating Characters) python...
  2. 中国航信官笔试计算机基础,中国航信笔试题目
  3. unity android本地推送,Unity安卓本地推送
  4. C++编程进阶7(何时使用成员函数模板,模板类的实参推断与类型转换、继承与数组)
  5. mysql 错误1930xc1_Mysql写入记录出现 Incorrect string value: '\xB4\xE7\xB1\xCA\xBC\xC7‘错误?(写入中文)...
  6. activiti 工作流_activiti工作流引擎入门
  7. 勒索软件可能已被“终极”解决
  8. GraphQL和REST对比时需要注意些什么
  9. Mongodb 请求处理流程
  10. Android CursorAdapter