FlycoTabLayout使用
step1:在module.gradle中添加
- dependencies{
- compile 'com.android.support:support-v4:23.1.1'
- compile 'com.nineoldandroids:library:2.4.0'
- compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
- compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.5.0@aar'
- }
- After v2.0.0
- dependencies{
- compile 'com.android.support:support-v4:23.1.1'
- compile 'com.nineoldandroids:library:2.4.0'
- compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.0.0@aar'
- }
step 2:建立TabEntity这里是tab的标题、选中的图标、未选中的图标
- package com.example.maoyh.myapplication.app.entity;
- import com.flyco.tablayout.listener.CustomTabEntity;
- public class TabEntity implements CustomTabEntity {
- public String title;
- public int selectedIcon;
- public int unSelectedIcon;
- public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
- this.title = title;
- this.selectedIcon = selectedIcon;
- this.unSelectedIcon = unSelectedIcon;
- }
- @Override
- public String getTabTitle() {
- return title;
- }
- @Override
- public int getTabSelectedIcon() {
- return selectedIcon;
- }
- @Override
- public int getTabUnselectedIcon() {
- return unSelectedIcon;
- }
- }
step 3:建立要关联的fragment
- package com.example.maoyh.myapplication.app.fragment;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.TextView;
- import com.example.maoyh.myapplication.app.R;
- /**
- * Created by MAOYH on 2016/3/2.
- */
- public class SimpleCardFragment extends Fragment {
- private String mTitle;
- public static SimpleCardFragment getInstance(String title) {
- SimpleCardFragment sf = new SimpleCardFragment();
- sf.mTitle = title;
- return sf;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.layout_fragment, null);
- TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
- card_title_tv.setText(mTitle);
- return v;
- }
- }
step 4:设置activity的layout
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- xmlns:tl="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
- <FrameLayout
- android:id="@+id/fl_change"
- android:layout_width="match_parent"
- android:layout_height="400dp">
- </FrameLayout>
- <com.flyco.tablayout.CommonTabLayout
- android:layout_alignBottom="@+id/fl_change"
- android:id="@+id/tl"
- android:layout_width="match_parent"
- android:layout_height="48dp"
- android:background="#ffffff"
- android:layout_alignParentBottom="true"
- tl:tl_iconGravity="LEFT"
- tl:tl_iconHeight="18dp"
- tl:tl_iconMargin="5dp"
- tl:tl_iconWidth="18dp"
- tl:tl_indicator_bounce_enable="true"
- tl:tl_indicator_color="#2C97DE"
- tl:tl_indicator_gravity="BOTTOM"
- tl:tl_indicator_height="0dp"
- tl:tl_textSelectColor="#2C97DE"
- tl:tl_textUnselectColor="#66000000"
- tl:tl_textsize="15sp"
- tl:tl_underline_color="#DDDDDD"
- tl:tl_underline_gravity="TOP"
- tl:tl_underline_height="1dp"/>
- </RelativeLayout>
step 5:fragment的layout
step 6:编码activity
- package com.example.maoyh.myapplication.app.activity;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v7.app.AppCompatActivity;
- import com.example.maoyh.myapplication.app.R;
- import com.example.maoyh.myapplication.app.entity.TabEntity;
- import com.example.maoyh.myapplication.app.fragment.SimpleCardFragment;
- import com.flyco.tablayout.CommonTabLayout;
- import com.flyco.tablayout.listener.CustomTabEntity;
- import java.util.ArrayList;
- public class MainActivity extends AppCompatActivity {
- private ArrayList<Fragment> mFragments = new ArrayList<>();
- private CommonTabLayout mTabLayout;
- private String[] mTitles = {"首页", "消息", "联系人", "我的"};
- private int[] mIconUnselectIds = {
- R.mipmap.tab_home_unselect, R.mipmap.tab_speech_unselect,
- R.mipmap.tab_contact_unselect, R.mipmap.tab_more_unselect};
- private int[] mIconSelectIds = {
- R.mipmap.tab_home_select, R.mipmap.tab_speech_select,
- R.mipmap.tab_contact_select, R.mipmap.tab_more_select};
- //tab的标题、选中图标、未选中图标
- private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- initData();
- initView();
- //给tab设置数据和关联的fragment
- mTabLayout.setTabData(mTabEntities, this, R.id.fl_change, mFragments);
- //设置红点
- mTabLayout.showDot(1);
- }
- private void initView() {
- mTabLayout = (CommonTabLayout) findViewById(R.id.tl);
- }
- private void initData() {
- for (String title : mTitles) {
- mFragments.add(SimpleCardFragment.getInstance( title));
- }
- //设置tab的标题、选中图标、未选中图标
- for (int i = 0; i < mTitles.length; i++) {
- mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
- }
- }
- }
FlycoTabLayout使用相关推荐
- 《Android 开源库》 FlycoTabLayout 从头到脚
简介 FlycoTabLayout,是一个比Google原生TabLayout 功能更强大的TabLayout库.目前有3种TabLayout: SlidingTabLayout CommonTabL ...
- FlycoTabLayout第三方控件设置选中放大
github地址:https://github.com/H07000223/FlycoTabLayout <com.flyco.tablayout.SlidingTabLayoutandroid ...
- FlycoTabLayout - SegmentTabLayout的使用
一:导入依赖: implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' 二:布局文件: 布局文件:SegmentTabLay ...
- 最新最全的 Android 开源项目合集(一)
原文链接:https://github.com/opendigg/awesome-github-android-ui 抽屉菜单 MaterialDrawer ★7337 - 安卓抽屉效果实现方案 Si ...
- 15类Android通用流行框架
15类Android通用流行框架 Android流行框架 缓存 DiskLruCache Java实现基于LRU的磁盘缓存 图片加载 Android Universal Image Loader 一个 ...
- Android开发常用开源框架3
AndroidImageSlider Android-ConvenientBanner DecentBanner AndroidSwipeLayout 为对象提供滑动功能,例如滑动删除. AirMap ...
- Android 开源库和项目 2
1.带尾巴的RecyclerViewPager 特点:1.像viewPager一样滑动一次就滑动一页 2.像画廊gallery一样,滑动一次可以滑动很多页 3.竖向滑动 4.支持点击事件,没有错乱 ...
- Android常用开源框架
快速索引 框架名称 上榜关键字 1.Retrofit 网络 2.okhttp 网络 3.Butter Knife 代码模板 4.MPAndroidChart 图表 5.glide 图片 6.leakc ...
- tablayout支持改变选中文字大小,支持左右滑动,支持viewpager,支持三角可移动指示器...
TabLayout [简书地址] (https://www.jianshu.com/p/2c3f868266e8) 基于大神的FlycoTabLayout [传送地址和基本用法](https://g ...
最新文章
- mysql 数据库连接字符串,mysql基本语句和连接字符串_数据库技巧
- CMake编译Widget UI Qt程序
- PyQt5 Introduction and components
- Java 重定位 —— redirect:
- 阿里云原生多模数据库Lindorm联合东软云科技,赋能车联网数字化运营运维创新升级
- [POJ1338]Ugly Numbers
- 在ThoughtWorks工作12年的技术主管,所总结的12条技术人经验
- 【设计模式】五、单例模式(独一无二的对象)
- 链表 队列 基本概念 为什么使用二叉查找树 抽象数据类型
- livechart 只显示 y 值_【科研工具51】谷歌,谷歌学术,Scihub有效网址检索软件——Y学术...
- (转)linux下vi编辑器编写C语言的配置
- oracle导出自增设置,oracle008:oracle自增,自适应,数据闪回,导入导出
- 《Tomcat权威指南》读书笔记
- Centos7搭建pptp一键安装脚本
- 捡到iphone6怎么解锁_赛博朋克2077前期手枪用哪个好?2077节制结局及银杯节制解锁条件...
- C++开源日志库选择
- 仓库管理软件中的账套是什么意思
- MySQL 5.7(windows 64位)下载安装
- 微信小程序tabbar消失_微信小程序tabBar底部导航 不显示问题解析
- MATLAB中Imcrop函数的用法
热门文章
- 无重复最长子串python_leetCode 无重复字符的最长子串 python(Longest Substring Without Repeating Characters) python...
- 中国航信官笔试计算机基础,中国航信笔试题目
- unity android本地推送,Unity安卓本地推送
- C++编程进阶7(何时使用成员函数模板,模板类的实参推断与类型转换、继承与数组)
- mysql 错误1930xc1_Mysql写入记录出现 Incorrect string value: '\xB4\xE7\xB1\xCA\xBC\xC7‘错误?(写入中文)...
- activiti 工作流_activiti工作流引擎入门
- 勒索软件可能已被“终极”解决
- GraphQL和REST对比时需要注意些什么
- Mongodb 请求处理流程
- Android CursorAdapter