├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── shanyao
│ │ └── tabpagerindicatordemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── shanyao
│ │ │ └── tabpagerindicatordemo
│ │ │ ├── FragmentFactory.java
│ │ │ ├── ShanYaoApplication.java
│ │ │ ├── activity
│ │ │ ├── MainActivity.java
│ │ │ ├── NoWeightExpandNoSame.java
│ │ │ ├── NoWeightExpandSame.java
│ │ │ ├── NoWeightNoExpandNoSame.java
│ │ │ ├── NoWeightNoExpandSame.java
│ │ │ ├── WeightNoExpandNoSame.java
│ │ │ └── WeightNoExpandSame.java
│ │ │ ├── fragment
│ │ │ ├── AFragment.java
│ │ │ ├── BFragment.java
│ │ │ ├── CFragment.java
│ │ │ ├── DFragment.java
│ │ │ ├── EFragment.java
│ │ │ ├── FFragment.java
│ │ │ ├── GFragment.java
│ │ │ ├── HFragment.java
│ │ │ ├── IFragment.java
│ │ │ ├── JFragment.java
│ │ │ ├── KFragment.java
│ │ │ ├── LFragment.java
│ │ │ ├── MFragment.java
│ │ │ └── NFragment.java
│ │ │ └── utils
│ │ │ └── CommonUtils.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── viewpager_indicator.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── shanyao
│ └── tabpagerindicatordemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gif
├── 1.gif
├── 2.gif
├── 3.gif
├── 4.gif
├── 5.gif
└── 6.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── tabpagerindictor
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── shanyao
│ └── tabpagerindictor
│ └── ApplicationTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── shanyao
│ │ └── tabpagerindictor
│ │ └── TabPageIndicator.java
└── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
└── test
└── java
└── shanyao
└── tabpagerindictor
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | TabPagerIndicatorDemo
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #TabPagerIndicator
2 | 一个强大的顶部标题导航栏,支持6种不同的模式
3 |
4 | 先来看下效果,再看使用方法
5 | ####一:MODE_WEIGHT_NOEXPAND_SAME
6 | 几个标题均分宽度,不能扩展,底部导航线跟标题宽度一致
7 |
8 | 
9 |
10 | ####二:MODE_WEIGHT_NOEXPAND_NOSAME
11 | 几个标题均分宽度,不能扩展,底部导航线跟标题宽度不一致
12 |
13 | 
14 |
15 | ####三:MODE_NOWEIGHT_NOEXPAND_SAME
16 | 标题不均分宽度,不能扩展,底部导航线跟标题宽度一致
17 |
18 | 
19 |
20 | ####四:MODE_NOWEIGHT_NOEXPAND_NOSAME
21 | 标题不均分宽度,不能扩展,底部导航线跟标题宽度不一致
22 |
23 | 
24 |
25 | ####五:MODE_NOWEIGHT_EXPAND_SAME
26 | 标题不均分宽度,能扩展,底部导航线跟标题宽度一致
27 |
28 | 
29 |
30 | ####六:MODE_NOWEIGHT_EXPAND_NOSAME
31 | 标题不均分宽度,能扩展,底部导航线跟标题宽度不一致
32 |
33 | 
34 |
35 | ##使用方法
36 | 一般来说这个类是ViewPager+TabPagerIndicator+Fragment来使用的
37 |
38 | ##### 1. 关联类库
39 | 首先,下载我上面的TabPagerIndicatorDemo,然后将里面的tabpagerindicator类库import Module到你的项目,并关联
40 | ##### 2. xml布局
41 | ```Java
42 |
43 |
48 |
49 |
54 |
59 |
60 | ```
61 | ##### 3. 代码使用
62 | ```Java
63 | @Override
64 | public void onCreate(Bundle savedInstanceState) {
65 | super.onCreate(savedInstanceState);
66 | setContentView(R.layout.viewpager_indicator);
67 | indicator = (TabPageIndicator)findViewById(R.id.indicator);
68 | viewPager = (ViewPager)findViewById(R.id.viewPager);
69 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
70 |
71 | viewPager.setAdapter(adapter);// 设置adapter
72 | indicator.setViewPager(viewPager);// 绑定indicator
73 |
74 | setTabPagerIndicator();
75 | }
76 | /**
77 | * 通过一些set方法,设置控件的属性
78 | */
79 | private void setTabPagerIndicator() {
80 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_WEIGHT_NOEXPAND_SAME);// 设置模式,一定要先设置模式
81 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
82 | indicator.setDividerPadding(10);//设置
83 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
84 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
85 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
86 | indicator.setTextSize(16);// 设置字体大小
87 | }
88 | ```
89 | ###常用方法说明
90 | ```Java
91 | setIndicatorMode()//设置控件的模式,上面是提到的6种模式
92 | setDividerColor()//设置两个标题之间的竖直分割线的颜色,如果不需要显示这个,设置颜色为透明即可
93 | setDividerPadding()//设置中间竖线上下的padding值
94 | setIndicatorColor()//设置底部导航线的颜色,就是上面演示图的绿色导航线
95 | setIndicatorHeight()// 设置底部导航线的高度
96 | setDividerPadding()// 设置Tab标题之间的间距
97 | setTextColorSelected()//设置tab标题选中的颜色
98 | setTextColor()//设置tab标题未被选中的颜色
99 | setTextSize()//设置字体的大小
100 | setUnderlineColor()// 设置最下面一条的横线的颜色
101 | setUnderlineHeight()//设置最下面一条的横线的高度
102 | setScrollOffset()// 这个方法是当选择MODE_NOWEIGHT_EXPAND_NOSAME和MODE_NOWEIGHT_EXPAND_SAME这两个模式的时候有作用
103 | 具体作用大家,可以下载Demo自己试一试
104 |
105 | ```
106 | ######可能还有一些不是常用的方法,大家可以自己下载Demo去试试
107 |
108 | ###我的博客
109 | [我的博客](http://blog.csdn.net/shan_yao)
110 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "shanyao.tabpagerindicatordemo"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.1'
26 | compile project(':tabpagerindictor')
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\program\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/shanyao/tabpagerindicatordemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/FragmentFactory.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | import shanyao.tabpagerindicatordemo.fragment.AFragment;
6 | import shanyao.tabpagerindicatordemo.fragment.BFragment;
7 | import shanyao.tabpagerindicatordemo.fragment.CFragment;
8 | import shanyao.tabpagerindicatordemo.fragment.DFragment;
9 | import shanyao.tabpagerindicatordemo.fragment.EFragment;
10 | import shanyao.tabpagerindicatordemo.fragment.FFragment;
11 | import shanyao.tabpagerindicatordemo.fragment.GFragment;
12 | import shanyao.tabpagerindicatordemo.fragment.HFragment;
13 | import shanyao.tabpagerindicatordemo.fragment.IFragment;
14 | import shanyao.tabpagerindicatordemo.fragment.JFragment;
15 | import shanyao.tabpagerindicatordemo.fragment.KFragment;
16 | import shanyao.tabpagerindicatordemo.fragment.LFragment;
17 | import shanyao.tabpagerindicatordemo.fragment.MFragment;
18 | import shanyao.tabpagerindicatordemo.fragment.NFragment;
19 |
20 |
21 | /**
22 | * Created by shan_yao on 2016/6/17.
23 | */
24 | public class FragmentFactory {
25 | public static Fragment createForNoExpand(int position) {
26 | Fragment fragment = null;
27 | switch (position) {
28 | case 0:
29 | fragment = new AFragment();
30 | break;
31 | case 1:
32 | fragment = new BFragment();
33 | break;
34 | case 2:
35 | fragment = new CFragment();
36 | break;
37 | }
38 | return fragment;
39 | }
40 |
41 | public static Fragment createForExpand(int position) {
42 | Fragment fragment = null;
43 | switch (position) {
44 | case 0:
45 | fragment = new DFragment();
46 | break;
47 | case 1:
48 | fragment = new EFragment();
49 | break;
50 | case 2:
51 | fragment = new FFragment();
52 | break;
53 | case 3:
54 | fragment = new GFragment();
55 | break;
56 | case 4:
57 | fragment = new HFragment();
58 | break;
59 | case 5:
60 | fragment = new IFragment();
61 | break;
62 | case 6:
63 | fragment = new JFragment();
64 | break;
65 | case 7:
66 | fragment = new KFragment();
67 | break;
68 | case 8:
69 | fragment = new LFragment();
70 | break;
71 | case 9:
72 | fragment = new MFragment();
73 | break;
74 | case 10:
75 | fragment = new NFragment();
76 | break;
77 | }
78 | return fragment;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/ShanYaoApplication.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | public class ShanYaoApplication extends Application {
7 | private static Context mContext;
8 | @Override
9 | public void onCreate() {
10 | super.onCreate();
11 | mContext = this;
12 | }
13 |
14 | /**
15 | * 获取全局的context
16 | */
17 | public static Context getContext() {
18 | return mContext;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import shanyao.tabpagerindicatordemo.R;
9 |
10 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 | findViewById(R.id.MODE_WEIGHT_NOEXPAND_SAME).setOnClickListener(this);
17 | findViewById(R.id.MODE_WEIGHT_NOEXPAND_NOSAME).setOnClickListener(this);
18 | findViewById(R.id.MODE_NOWEIGHT_NOEXPAND_SAME).setOnClickListener(this);
19 | findViewById(R.id.MODE_NOWEIGHT_NOEXPAND_NOSAME).setOnClickListener(this);
20 | findViewById(R.id.MODE_NOWEIGHT_EXPAND_SAME).setOnClickListener(this);
21 | findViewById(R.id.MODE_NOWEIGHT_EXPAND_NOSAME).setOnClickListener(this);
22 | }
23 |
24 | @Override
25 | public void onClick(View v) {
26 | switch (v.getId()) {
27 | case R.id.MODE_WEIGHT_NOEXPAND_SAME:
28 | startActivity(new Intent(MainActivity.this, WeightNoExpandSame.class));
29 | break;
30 | case R.id.MODE_WEIGHT_NOEXPAND_NOSAME:
31 | startActivity(new Intent(MainActivity.this, WeightNoExpandNoSame.class));
32 | break;
33 | case R.id.MODE_NOWEIGHT_NOEXPAND_SAME:
34 | startActivity(new Intent(MainActivity.this, NoWeightNoExpandSame.class));
35 | break;
36 | case R.id.MODE_NOWEIGHT_NOEXPAND_NOSAME:
37 | startActivity(new Intent(MainActivity.this, NoWeightNoExpandNoSame.class));
38 | break;
39 | case R.id.MODE_NOWEIGHT_EXPAND_SAME:
40 | startActivity(new Intent(MainActivity.this, NoWeightExpandSame.class));
41 | break;
42 | case R.id.MODE_NOWEIGHT_EXPAND_NOSAME:
43 | startActivity(new Intent(MainActivity.this, NoWeightExpandNoSame.class));
44 | break;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/NoWeightExpandNoSame.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 |
11 | import shanyao.tabpagerindicatordemo.R;
12 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
13 | import shanyao.tabpagerindicatordemo.FragmentFactory;
14 | import shanyao.tabpagerindicatordemo.utils.CommonUtils;
15 | import shanyao.tabpagerindictor.TabPageIndicator;
16 |
17 | /**
18 | * Created by HuaChing904 on 2016/6/23.
19 | */
20 | public class NoWeightExpandNoSame extends FragmentActivity {
21 |
22 | private TabPageIndicator indicator;
23 | private ViewPager viewPager;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.viewpager_indicator);
29 | indicator = (TabPageIndicator)findViewById(R.id.indicator);
30 | viewPager = (ViewPager)findViewById(R.id.viewPager);
31 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
32 | viewPager.setAdapter(adapter);
33 | indicator.setViewPager(viewPager);
34 | setTabPagerIndicator();
35 | }
36 |
37 | private void setTabPagerIndicator() {
38 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_NOWEIGHT_EXPAND_NOSAME);// 设置模式,一定要先设置模式
39 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
40 | indicator.setDividerPadding(CommonUtils.dip2px(ShanYaoApplication.getContext(), 10));
41 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
42 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
43 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
44 | indicator.setTextSize(CommonUtils.sp2px(ShanYaoApplication.getContext(), 16));// 设置字体大小
45 | }
46 |
47 | class BasePagerAdapter extends FragmentPagerAdapter {
48 | String[] titles;
49 |
50 | public BasePagerAdapter(FragmentManager fm) {
51 | super(fm);
52 | this.titles = CommonUtils.getStringArray(R.array.expand_titles);
53 | }
54 |
55 | @Override
56 | public Fragment getItem(int position) {
57 | return FragmentFactory.createForExpand(position);
58 | }
59 |
60 | @Override
61 | public int getCount() {
62 | return titles.length;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return titles[position];
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/NoWeightExpandSame.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 |
11 | import shanyao.tabpagerindicatordemo.R;
12 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
13 | import shanyao.tabpagerindicatordemo.FragmentFactory;
14 | import shanyao.tabpagerindicatordemo.utils.CommonUtils;
15 | import shanyao.tabpagerindictor.TabPageIndicator;
16 |
17 | /**
18 | * Created by HuaChing904 on 2016/6/23.
19 | */
20 | public class NoWeightExpandSame extends FragmentActivity {
21 |
22 | private TabPageIndicator indicator;
23 | private ViewPager viewPager;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.viewpager_indicator);
29 | indicator = (TabPageIndicator) findViewById(R.id.indicator);
30 | viewPager = (ViewPager) findViewById(R.id.viewPager);
31 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
32 | viewPager.setAdapter(adapter);
33 | indicator.setViewPager(viewPager);
34 | setTabPagerIndicator();
35 | }
36 |
37 | private void setTabPagerIndicator() {
38 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_NOWEIGHT_EXPAND_SAME);// 设置模式,一定要先设置模式
39 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
40 | indicator.setDividerPadding(CommonUtils.dip2px(ShanYaoApplication.getContext(), 10));
41 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
42 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
43 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
44 | indicator.setTextSize(CommonUtils.sp2px(ShanYaoApplication.getContext(), 16));// 设置字体大小
45 | }
46 |
47 | class BasePagerAdapter extends FragmentStatePagerAdapter {
48 | String[] titles;
49 |
50 | public BasePagerAdapter(FragmentManager fm) {
51 | super(fm);
52 | this.titles = CommonUtils.getStringArray(R.array.expand_titles);
53 | }
54 |
55 | @Override
56 | public Fragment getItem(int position) {
57 | return FragmentFactory.createForExpand(position);
58 | }
59 |
60 | @Override
61 | public int getCount() {
62 | return titles.length;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return titles[position];
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/NoWeightNoExpandNoSame.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 |
11 | import shanyao.tabpagerindicatordemo.R;
12 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
13 | import shanyao.tabpagerindicatordemo.FragmentFactory;
14 | import shanyao.tabpagerindicatordemo.utils.CommonUtils;
15 | import shanyao.tabpagerindictor.TabPageIndicator;
16 |
17 | /**
18 | * Created by HuaChing904 on 2016/6/23.
19 | */
20 | public class NoWeightNoExpandNoSame extends FragmentActivity {
21 |
22 | private TabPageIndicator indicator;
23 | private ViewPager viewPager;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.viewpager_indicator);
29 | indicator = (TabPageIndicator) findViewById(R.id.indicator);
30 | viewPager = (ViewPager) findViewById(R.id.viewPager);
31 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
32 | viewPager.setAdapter(adapter);
33 | indicator.setViewPager(viewPager);
34 | setTabPagerIndicator();
35 | }
36 |
37 | private void setTabPagerIndicator() {
38 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_NOWEIGHT_NOEXPAND_NOSAME);// 设置模式,一定要先设置模式
39 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
40 | indicator.setDividerPadding(CommonUtils.dip2px(ShanYaoApplication.getContext(), 10));
41 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
42 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
43 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
44 | indicator.setTextSize(CommonUtils.sp2px(ShanYaoApplication.getContext(), 16));// 设置字体大小
45 | }
46 |
47 | class BasePagerAdapter extends FragmentStatePagerAdapter {
48 | String[] titles;
49 |
50 | public BasePagerAdapter(FragmentManager fm) {
51 | super(fm);
52 | this.titles = CommonUtils.getStringArray(R.array.no_expand_titles);
53 | }
54 |
55 | @Override
56 | public Fragment getItem(int position) {
57 | return FragmentFactory.createForNoExpand(position);
58 | }
59 |
60 | @Override
61 | public int getCount() {
62 | return titles.length;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return titles[position];
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/NoWeightNoExpandSame.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 |
11 | import shanyao.tabpagerindicatordemo.R;
12 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
13 | import shanyao.tabpagerindicatordemo.FragmentFactory;
14 | import shanyao.tabpagerindicatordemo.utils.CommonUtils;
15 | import shanyao.tabpagerindictor.TabPageIndicator;
16 |
17 | /**
18 | * Created by HuaChing904 on 2016/6/23.
19 | */
20 | public class NoWeightNoExpandSame extends FragmentActivity {
21 |
22 | private TabPageIndicator indicator;
23 | private ViewPager viewPager;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.viewpager_indicator);
29 | indicator = (TabPageIndicator) findViewById(R.id.indicator);
30 | viewPager = (ViewPager) findViewById(R.id.viewPager);
31 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
32 | viewPager.setAdapter(adapter);
33 | indicator.setViewPager(viewPager);
34 | setTabPagerIndicator();
35 | }
36 |
37 | private void setTabPagerIndicator() {
38 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_NOWEIGHT_NOEXPAND_SAME);// 设置模式,一定要先设置模式
39 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
40 | indicator.setDividerPadding(CommonUtils.dip2px(ShanYaoApplication.getContext(), 10));
41 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
42 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
43 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
44 | indicator.setTextSize(CommonUtils.sp2px(ShanYaoApplication.getContext(), 16));// 设置字体大小
45 | }
46 |
47 | class BasePagerAdapter extends FragmentStatePagerAdapter {
48 | String[] titles;
49 |
50 | public BasePagerAdapter(FragmentManager fm) {
51 | super(fm);
52 | this.titles = CommonUtils.getStringArray(R.array.no_expand_titles);
53 | }
54 |
55 | @Override
56 | public Fragment getItem(int position) {
57 | return FragmentFactory.createForNoExpand(position);
58 | }
59 |
60 | @Override
61 | public int getCount() {
62 | return titles.length;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return titles[position];
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/WeightNoExpandNoSame.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 |
11 | import shanyao.tabpagerindicatordemo.R;
12 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
13 | import shanyao.tabpagerindicatordemo.FragmentFactory;
14 | import shanyao.tabpagerindicatordemo.utils.CommonUtils;
15 | import shanyao.tabpagerindictor.TabPageIndicator;
16 |
17 | /**
18 | * Created by HuaChing904 on 2016/6/23.
19 | */
20 | public class WeightNoExpandNoSame extends FragmentActivity {
21 |
22 | private TabPageIndicator indicator;
23 | private ViewPager viewPager;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.viewpager_indicator);
29 | indicator = (TabPageIndicator)findViewById(R.id.indicator);
30 | viewPager = (ViewPager)findViewById(R.id.viewPager);
31 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
32 | viewPager.setAdapter(adapter);
33 | indicator.setViewPager(viewPager);
34 | setTabPagerIndicator();
35 | }
36 |
37 | private void setTabPagerIndicator() {
38 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_WEIGHT_NOEXPAND_NOSAME);// 设置模式,一定要先设置模式
39 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
40 | indicator.setDividerPadding(CommonUtils.dip2px(ShanYaoApplication.getContext(), 10));
41 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
42 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
43 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
44 | indicator.setTextSize(CommonUtils.sp2px(ShanYaoApplication.getContext(), 16));// 设置字体大小
45 | }
46 |
47 | class BasePagerAdapter extends FragmentStatePagerAdapter {
48 | String[] titles;
49 |
50 | public BasePagerAdapter(FragmentManager fm) {
51 | super(fm);
52 | this.titles = CommonUtils.getStringArray(R.array.no_expand_titles);
53 | }
54 |
55 | @Override
56 | public Fragment getItem(int position) {
57 | return FragmentFactory.createForNoExpand(position);
58 | }
59 |
60 | @Override
61 | public int getCount() {
62 | return titles.length;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return titles[position];
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/activity/WeightNoExpandSame.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 |
11 | import shanyao.tabpagerindicatordemo.R;
12 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
13 | import shanyao.tabpagerindicatordemo.FragmentFactory;
14 | import shanyao.tabpagerindicatordemo.utils.CommonUtils;
15 | import shanyao.tabpagerindictor.TabPageIndicator;
16 |
17 | /**
18 | * Created by HuaChing904 on 2016/6/23.
19 | */
20 | public class WeightNoExpandSame extends FragmentActivity {
21 |
22 | private TabPageIndicator indicator;
23 | private ViewPager viewPager;
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.viewpager_indicator);
29 | indicator = (TabPageIndicator)findViewById(R.id.indicator);
30 | viewPager = (ViewPager)findViewById(R.id.viewPager);
31 | BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
32 | viewPager.setAdapter(adapter);
33 | indicator.setViewPager(viewPager);
34 | setTabPagerIndicator();
35 | }
36 |
37 | private void setTabPagerIndicator() {
38 | indicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_WEIGHT_NOEXPAND_SAME);// 设置模式,一定要先设置模式
39 | indicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
40 | indicator.setDividerPadding(CommonUtils.dip2px(ShanYaoApplication.getContext(), 10));
41 | indicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
42 | indicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
43 | indicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
44 | indicator.setTextSize(CommonUtils.sp2px(ShanYaoApplication.getContext(), 16));// 设置字体大小
45 | }
46 |
47 | class BasePagerAdapter extends FragmentPagerAdapter {
48 | String[] titles;
49 |
50 | public BasePagerAdapter(FragmentManager fm) {
51 | super(fm);
52 | this.titles = CommonUtils.getStringArray(R.array.no_expand_titles);
53 | }
54 |
55 | @Override
56 | public Fragment getItem(int position) {
57 | return FragmentFactory.createForNoExpand(position);
58 | }
59 |
60 | @Override
61 | public int getCount() {
62 | return titles.length;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return titles[position];
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/AFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shaoyao on 2016/6/17.
15 | */
16 | public class AFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("全部订单");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/BFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class BFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("当前订单");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/CFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class CFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("历史订单");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/DFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class DFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("头条");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/EFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class EFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("娱乐");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/FFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class FFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("体育");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/GFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class GFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("网易号");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/HFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class HFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("北京");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/IFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class IFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("财经");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/JFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class JFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("科技");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/KFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class KFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("汽车");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/LFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class LFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("时尚");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/MFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class MFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("图片");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/fragment/NFragment.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.Gravity;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | /**
14 | * Created by shanyao on 2016/6/17.
15 | */
16 | public class NFragment extends Fragment {
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | TextView view = new TextView(getActivity());
21 | view.setGravity(Gravity.CENTER);
22 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
23 | view.setText("跟帖");
24 | view.setTextColor(Color.RED);
25 | view.setTextSize(50);
26 | return view;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/shanyao/tabpagerindicatordemo/utils/CommonUtils.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.drawable.Drawable;
6 |
7 | import shanyao.tabpagerindicatordemo.ShanYaoApplication;
8 |
9 |
10 | public class CommonUtils {
11 | /**
12 | * dip转化成px
13 | */
14 | public static int dip2px(Context context, float dpValue) {
15 | final float scale = context.getResources().getDisplayMetrics().density;
16 | return (int) (dpValue * scale + 0.5f);
17 | }
18 |
19 | /**
20 | * px转化成dip
21 | */
22 | public static int px2dip(Context context, float pxValue) {
23 | final float scale = context.getResources().getDisplayMetrics().density;
24 | return (int) (pxValue / scale + 0.5f);
25 | }
26 |
27 | /**
28 | * px转化成sp
29 | */
30 | public static int px2sp(Context context, float pxValue) {
31 | final float scale = context.getResources().getDisplayMetrics().density;
32 | return (int) (pxValue / scale + 0.5f);
33 | }
34 |
35 | /**
36 | * sp转化成px
37 | */
38 | public static int sp2px(Context context, float spValue) {
39 | final float scale = context.getResources().getDisplayMetrics().density;
40 | return (int) (spValue * scale + 0.5f);
41 | }
42 |
43 | /**
44 | * 获取Resource对象
45 | */
46 | public static Resources getResources() {
47 | return ShanYaoApplication.getContext().getResources();
48 | }
49 |
50 | /**
51 | * 获取Drawable资源
52 | */
53 | public static Drawable getDrawable(int resId) {
54 | return getResources().getDrawable(resId);
55 | }
56 |
57 | /**
58 | * 获取字符串资源
59 | */
60 | public static String getString(int resId) {
61 | return getResources().getString(resId);
62 | }
63 |
64 | /**
65 | * 获取color资源
66 | */
67 | public static int getColor(int resId) {
68 | return getResources().getColor(resId);
69 | }
70 |
71 | /**
72 | * 获取dimens资源
73 | */
74 | public static float getDimens(int resId) {
75 | return getResources().getDimension(resId);
76 | }
77 |
78 | /**
79 | * 获取字符串数组资源
80 | */
81 | public static String[] getStringArray(int resId) {
82 | return getResources().getStringArray(resId);
83 | }
84 | }
85 |
86 |
87 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
30 |
31 |
36 |
37 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/viewpager_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TabPagerIndicatorDemo
3 |
4 | - 全部订单
5 | - 当前订单
6 | - 历史订单
7 |
8 |
9 | - 头条
10 | - 娱乐
11 | - 体育
12 | - 网易号
13 | - 北京
14 | - 财经
15 | - 科技
16 | - 汽车
17 | - 时尚
18 | - 图片
19 | - 跟帖
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/shanyao/tabpagerindicatordemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindicatordemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gif/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gif/1.gif
--------------------------------------------------------------------------------
/gif/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gif/2.gif
--------------------------------------------------------------------------------
/gif/3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gif/3.gif
--------------------------------------------------------------------------------
/gif/4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gif/4.gif
--------------------------------------------------------------------------------
/gif/5.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gif/5.gif
--------------------------------------------------------------------------------
/gif/6.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gif/6.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanyao0/TabPagerIndicatorDemo/e6e91dd081b8ca1457c6f72b0effa5556c34f189/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':tabpagerindictor'
2 |
--------------------------------------------------------------------------------
/tabpagerindictor/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tabpagerindictor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.2.1'
25 | }
26 |
--------------------------------------------------------------------------------
/tabpagerindictor/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\program\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/tabpagerindictor/src/androidTest/java/shanyao/tabpagerindictor/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindictor;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/tabpagerindictor/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tabpagerindictor/src/main/java/shanyao/tabpagerindictor/TabPageIndicator.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindictor;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Paint.Style;
10 | import android.os.Build;
11 | import android.os.Parcel;
12 | import android.os.Parcelable;
13 | import android.support.v4.view.ViewPager;
14 | import android.support.v4.view.ViewPager.OnPageChangeListener;
15 | import android.util.AttributeSet;
16 | import android.util.DisplayMetrics;
17 | import android.util.Log;
18 | import android.util.TypedValue;
19 | import android.view.Gravity;
20 | import android.view.View;
21 | import android.view.ViewTreeObserver.OnGlobalLayoutListener;
22 | import android.widget.HorizontalScrollView;
23 | import android.widget.LinearLayout;
24 | import android.widget.TextView;
25 |
26 | import java.util.Locale;
27 |
28 | public class TabPageIndicator extends HorizontalScrollView {
29 | private Context mContext;
30 | private int[] widths;
31 |
32 | private static final int[] ATTRS = new int[]{
33 | android.R.attr.textSize,
34 | android.R.attr.textColor
35 | };
36 |
37 | private LinearLayout.LayoutParams wrapTabLayoutParams;
38 | private LinearLayout.LayoutParams weightTabLayoutParams;
39 |
40 | private final PageListener pageListener = new PageListener();
41 | public OnPageChangeListener delegatePageListener;
42 |
43 | private LinearLayout tabsContainer;
44 | private ViewPager pager;
45 |
46 | private int tabCount;
47 |
48 |
49 | private int currentPosition = 0;
50 | private float currentPositionOffset = 0f;
51 |
52 | private Paint rectPaint;
53 | private Paint dividerPaint;
54 |
55 | private boolean checkedTabWidths = false;
56 |
57 | private int indicatorColor = Color.parseColor("#ffffff");//指示线的颜色 #0075E7
58 | private int underlineColor = 0xFFdcdcdc;// 默认指示线的颜色
59 | private int dividerColor = 0x00000000;// 分割线的颜色
60 |
61 | private boolean isSameLine;// 设置导航先是否跟文字长度一至
62 | private boolean textAllCaps;
63 |
64 | private boolean isExpand;// 是否可扩展
65 | private boolean isExpandSameLine;// 可扩展并且导标一致
66 |
67 | private int scrollOffset = 10;// 当显示多个tab时,底部导航线距离左侧的位移,默认是10,请不要太小
68 | private int indicatorHeight = 2;//指示线的高度
69 | private int underlineHeight = 1;// 默认指示线的高度
70 | private int dividerPadding = 0;//竖线到下面的距离:可以通过设置indicator的高度设置下面横线和文字的距离
71 | private int tabPadding;// 标题的间距
72 | private int dividerWidth = 0;// 分割线的宽度
73 |
74 | private int indicatorPaddingLeft = 0;// 距离左边的距离
75 | private int indicatorPaddingRight = 0;// 距离右边的距离
76 |
77 | private int tabTextSize = 16;//标题的字体大小
78 | private int tabTextColor = 0xFF666666;// 标题未被选中时字体颜色
79 | private int tabTextColorSelected = Color.parseColor("#ffffff");// 标题被选中时字体颜色
80 |
81 | private int lastScrollX = 0;
82 |
83 | private int tabBackgroundResId;
84 | // = R.drawable.background_tab;//字体颜色的选择器
85 |
86 | private Locale locale;
87 |
88 | /**
89 | * 定义6种模式
90 | */
91 | public enum IndicatorMode {
92 | // 给枚举传入自定义的int值
93 | MODE_WEIGHT_NOEXPAND_SAME(0), // 平均分配,导航线跟标题相等
94 | MODE_WEIGHT_NOEXPAND_NOSAME(1), // 平均分配,导航线跟标题不相等
95 | MODE_NOWEIGHT_NOEXPAND_SAME(2),// 非平均分配,非扩展,导标相等
96 | MODE_NOWEIGHT_NOEXPAND_NOSAME(3),// 非平均分配,非扩展,导标不相等
97 | MODE_NOWEIGHT_EXPAND_SAME(4),// 可扩展,导标相等
98 | MODE_NOWEIGHT_EXPAND_NOSAME(5);// 不可扩展,导标不相等
99 | private int value;
100 |
101 | IndicatorMode(int value) {
102 | this.value = value;
103 | }
104 |
105 | public int getValue() {
106 | return value;
107 | }
108 | }
109 |
110 | private IndicatorMode currentIndicatorMode = IndicatorMode.MODE_WEIGHT_NOEXPAND_SAME;
111 |
112 |
113 | public TabPageIndicator(Context context) {
114 | this(context, null);
115 | this.mContext = context;
116 | }
117 |
118 | public TabPageIndicator(Context context, AttributeSet attrs) {
119 | this(context, attrs, 0);
120 | this.mContext = context;
121 | }
122 |
123 | public TabPageIndicator(Context context, AttributeSet attrs, int defStyle) {
124 | super(context, attrs, defStyle);
125 | this.mContext = context;
126 | setFillViewport(true);
127 | setWillNotDraw(false);
128 |
129 | tabsContainer = new LinearLayout(context);
130 | tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
131 | LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
132 | tabsContainer.setLayoutParams(layoutParams);
133 | addView(tabsContainer);
134 |
135 | DisplayMetrics dm = getResources().getDisplayMetrics();
136 |
137 | scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
138 | indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
139 | underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
140 | dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
141 | tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
142 | dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
143 | tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabTextSize, dm);
144 |
145 | // get system attrs (android:textSize and android:textColor)
146 |
147 | TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
148 |
149 | tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
150 | tabTextColor = a.getColor(R.styleable.PagerSlidingTab_indicatorColor, tabTextColor);
151 |
152 | a.recycle();
153 |
154 | // get custom attrs
155 |
156 | a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTab);
157 |
158 | indicatorColor = a.getColor(R.styleable.PagerSlidingTab_indicatorColor, indicatorColor);
159 | underlineColor = a.getColor(R.styleable.PagerSlidingTab_underlineColor, underlineColor);
160 | dividerColor = a.getColor(R.styleable.PagerSlidingTab_dividerColor, dividerColor);
161 | indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_indicatorHeight, indicatorHeight);
162 | underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_underlineHeight, underlineHeight);
163 | dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_pst_dividerPadding, dividerPadding);
164 | tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_tabPaddingLeftRight, tabPadding);
165 | tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTab_tabBackgrounds, tabBackgroundResId);
166 | // isSameLine = a.getBoolean(R.styleable.PagerSlidingTab_sameLine, isSameLine);
167 | scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_scrollOffset, scrollOffset);
168 | textAllCaps = a.getBoolean(R.styleable.PagerSlidingTab_pst_textAllCaps, textAllCaps);
169 |
170 | a.recycle();
171 |
172 | rectPaint = new Paint();
173 | rectPaint.setAntiAlias(true);
174 | rectPaint.setStyle(Style.FILL);
175 |
176 | dividerPaint = new Paint();
177 | dividerPaint.setAntiAlias(true);
178 | dividerPaint.setStrokeWidth(dividerWidth);
179 |
180 | wrapTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
181 | weightTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);
182 |
183 | if (locale == null) {
184 | locale = getResources().getConfiguration().locale;
185 | }
186 | }
187 |
188 |
189 | // 根据不同的Mode设置不同的展现效果
190 | public void setIndicatorMode(IndicatorMode indicatorMode) {
191 | switch (indicatorMode) {
192 | case MODE_WEIGHT_NOEXPAND_SAME:
193 | isExpand = false;
194 | isSameLine = true;
195 | break;
196 | case MODE_WEIGHT_NOEXPAND_NOSAME:
197 | isExpand = false;
198 | isSameLine = false;
199 | break;
200 | case MODE_NOWEIGHT_NOEXPAND_SAME:
201 | isExpand = false;
202 | isSameLine = true;
203 | isExpandSameLine = true;
204 | tabPadding = dip2px(10);
205 | break;
206 | case MODE_NOWEIGHT_NOEXPAND_NOSAME:
207 | isExpand = false;
208 | isSameLine = true;
209 | isExpandSameLine = true;
210 | tabPadding = dip2px(10);
211 | break;
212 | case MODE_NOWEIGHT_EXPAND_SAME:
213 | isExpand = true;
214 | isExpandSameLine = true;
215 | tabPadding = dip2px(10);
216 | break;
217 | case MODE_NOWEIGHT_EXPAND_NOSAME:
218 | isExpand = true;
219 | isExpandSameLine = false;
220 | tabPadding = dip2px(10);
221 | break;
222 | }
223 | this.currentIndicatorMode = indicatorMode;
224 | notifyDataSetChanged();
225 | }
226 |
227 | public void setViewPager(ViewPager pager) {
228 | this.pager = pager;
229 |
230 | if (pager.getAdapter() == null) {
231 | throw new IllegalStateException("ViewPager does not have adapter instance.");
232 | }
233 |
234 | pager.setOnPageChangeListener(pageListener);
235 |
236 | notifyDataSetChanged();
237 | }
238 |
239 | public void setOnPageChangeListener(OnPageChangeListener listener) {
240 | this.delegatePageListener = listener;
241 | }
242 |
243 | public void notifyDataSetChanged() {
244 |
245 | tabsContainer.removeAllViews();
246 |
247 | tabCount = pager.getAdapter().getCount();
248 |
249 | for (int i = 0; i < tabCount; i++) {
250 | addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
251 | }
252 |
253 | updateTabStyles();
254 |
255 | checkedTabWidths = false;
256 |
257 | getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
258 |
259 | @SuppressWarnings("deprecation")
260 | @SuppressLint("NewApi")
261 | @Override
262 | public void onGlobalLayout() {
263 |
264 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
265 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
266 | } else {
267 | getViewTreeObserver().removeOnGlobalLayoutListener(this);
268 | }
269 |
270 | currentPosition = pager.getCurrentItem();
271 | scrollToChild(currentPosition, 0);
272 | }
273 | });
274 |
275 | }
276 |
277 | private void addTextTab(final int position, String title) {
278 |
279 | TextView tab = new TextView(getContext());
280 | tab.setText(title);
281 | tab.setFocusable(true);
282 | tab.setGravity(Gravity.CENTER);
283 | tab.setSingleLine();
284 | tab.setOnClickListener(new OnClickListener() {
285 | @Override
286 | public void onClick(View v) {
287 | pager.setCurrentItem(position);
288 | }
289 | });
290 | if (isExpand && !isExpandSameLine) {
291 | tab.setPadding(tabPadding, 0, tabPadding, 0);
292 | } else {
293 | wrapTabLayoutParams.setMargins(tabPadding, 0, tabPadding, 0);
294 | weightTabLayoutParams.setMargins(tabPadding, 0, tabPadding, 0);
295 | }
296 | tabsContainer.addView(tab, position, isSameLine ? wrapTabLayoutParams : weightTabLayoutParams);
297 | }
298 |
299 | private void updateTabStyles() {
300 | widths = new int[tabCount];
301 | for (int i = 0; i < tabCount; i++) {
302 |
303 | View v = tabsContainer.getChildAt(i);
304 |
305 | if (v instanceof TextView) {
306 |
307 | TextView tab = (TextView) v;
308 | tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
309 | tab.setTextColor(i == 0 ? tabTextColorSelected : tabTextColor);
310 | //大小写切换
311 | if (textAllCaps) {
312 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
313 | tab.setAllCaps(true);
314 | } else {
315 | tab.setText(tab.getText().toString().toUpperCase(locale));
316 | }
317 | }
318 | }
319 | }
320 | }
321 |
322 | @Override
323 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
324 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
325 | if (isExpand) return;
326 |
327 | /**
328 | * 一下这些代码是为了在设置weight的情况下,导航线也能跟标题长度一致
329 | */
330 | int myWidth = getMeasuredWidth();// 其实就是屏幕的宽度
331 | int childWidth = 0;
332 | for (int i = 0; i < tabCount; i++) {
333 | childWidth += tabsContainer.getChildAt(i).getMeasuredWidth();
334 | if (widths[i] == 0) {
335 | widths[i] = tabsContainer.getChildAt(i).getMeasuredWidth();
336 | }
337 | }
338 | if (currentIndicatorMode == IndicatorMode.MODE_NOWEIGHT_NOEXPAND_SAME) {
339 | setIndicatorPaddingRight(myWidth - childWidth - tabPadding * 2 * tabCount);
340 | tabsContainer.setPadding(indicatorPaddingLeft, 0, indicatorPaddingRight, 0);
341 | }
342 | if (currentIndicatorMode == IndicatorMode.MODE_NOWEIGHT_NOEXPAND_NOSAME){
343 | setIndicatorPaddingRight(myWidth - childWidth - tabPadding * 2 * tabCount);
344 | tabsContainer.setPadding(indicatorPaddingLeft, 0, indicatorPaddingRight, 0);
345 | }
346 | if (!checkedTabWidths && childWidth > 0 && myWidth > 0) {
347 | // tab标题的长度为超过屏幕的宽度
348 | if (childWidth <= myWidth) {
349 | for (int i = 0; i < tabCount; i++) {
350 | tabsContainer.getChildAt(i).setLayoutParams(weightTabLayoutParams);
351 | }
352 | } else {
353 | for (int i = 0; i < tabCount; i++) {
354 | tabsContainer.getChildAt(i).setLayoutParams(wrapTabLayoutParams);
355 | }
356 | }
357 |
358 | checkedTabWidths = true;
359 | }
360 | }
361 |
362 | private void scrollToChild(int position, int offset) {
363 | if (tabCount == 0 || offset == 0) {
364 | return;
365 | }
366 |
367 | int newScrollX = tabsContainer.getChildAt(position).getLeft() + offset;
368 |
369 | if (position > 0 || offset > 0) {
370 | newScrollX -= scrollOffset;
371 | }
372 |
373 | if (newScrollX != lastScrollX) {
374 | lastScrollX = newScrollX;
375 | scrollTo(newScrollX, 0);
376 | }
377 |
378 | }
379 |
380 | @Override
381 | protected void onDraw(Canvas canvas) {
382 | super.onDraw(canvas);
383 | if (isInEditMode() || tabCount == 0) {
384 | return;
385 | }
386 |
387 | final int height = getHeight();
388 |
389 | /**
390 | * draw底部的导航线
391 | */
392 |
393 | rectPaint.setColor(indicatorColor);
394 | // 默认在Tab标题的下面
395 | View currentTab = tabsContainer.getChildAt(currentPosition);
396 | float currentOffWid;
397 | if (isExpand) {
398 | currentOffWid = 0;
399 | } else {
400 | currentOffWid = (currentTab.getWidth() - widths[currentPosition]) / 2;
401 | }
402 |
403 | float lineLeft = currentTab.getLeft() + currentOffWid;
404 | float lineRight = currentTab.getRight() - currentOffWid;
405 |
406 | // if there is an offset, start interpolating left and right coordinates between current and next tab
407 | if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
408 | View nextTab = tabsContainer.getChildAt(currentPosition + 1);
409 | float nextOffWid;
410 | if (isExpand) {
411 | nextOffWid = 0;
412 | } else {
413 | nextOffWid = (nextTab.getWidth() - widths[currentPosition + 1]) / 2;
414 | }
415 | final float nextTabLeft = nextTab.getLeft() + nextOffWid;
416 | final float nextTabRight = nextTab.getRight() - nextOffWid;
417 |
418 | lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
419 | lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
420 | }
421 | if (currentIndicatorMode == IndicatorMode.MODE_NOWEIGHT_NOEXPAND_NOSAME){
422 | canvas.drawRect(lineLeft-tabPadding, height - indicatorHeight, lineRight+tabPadding, height, rectPaint);
423 | }else{
424 | canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
425 | }
426 | // if(isExpand&&!isExpandSameLine){
427 | // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
428 | // }else{
429 | // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
430 | // }
431 | //线在顶端的情况
432 | // canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight, rectPaint);
433 |
434 | /**
435 | * draw underline
436 | */
437 |
438 | rectPaint.setColor(underlineColor);
439 | canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
440 |
441 | /**
442 | * draw divider:分割线
443 | */
444 | dividerPaint.setColor(dividerColor);
445 | for (int i = 0; i < tabCount - 1; i++) {
446 | View tab = tabsContainer.getChildAt(i);
447 | if (!isExpandSameLine) {
448 | canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
449 | } else {
450 | canvas.drawLine(tab.getRight() + tabPadding, dividerPadding, tab.getRight() + tabPadding, height - dividerPadding, dividerPaint);
451 | }
452 | }
453 | }
454 |
455 | private class PageListener implements OnPageChangeListener {
456 |
457 | @Override
458 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
459 |
460 | currentPosition = position;
461 | currentPositionOffset = positionOffset;
462 | Log.e("shanyao", positionOffset + "");
463 | scrollToChild(position, (int) (positionOffset * tabsContainer.getChildAt(position).getWidth()));
464 |
465 | invalidate();
466 |
467 | if (delegatePageListener != null) {
468 | delegatePageListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
469 | }
470 | }
471 |
472 | @Override
473 | public void onPageScrollStateChanged(int state) {
474 | if (state == ViewPager.SCROLL_STATE_IDLE) {
475 | scrollToChild(pager.getCurrentItem(), 0);
476 | }
477 |
478 | if (delegatePageListener != null) {
479 | delegatePageListener.onPageScrollStateChanged(state);
480 | }
481 | }
482 |
483 | @Override
484 | public void onPageSelected(int position) {
485 | if (delegatePageListener != null) {
486 | delegatePageListener.onPageSelected(position);
487 | }
488 |
489 | //使当前item高亮
490 | for (int i = 0; i < tabCount; i++) {
491 | View v = tabsContainer.getChildAt(i);
492 | if (v instanceof TextView) {
493 | TextView textView = (TextView) v;
494 | textView.setTextColor(i == pager.getCurrentItem() ? tabTextColorSelected : tabTextColor);
495 | }
496 | }
497 | }
498 | }
499 |
500 | public void setIndicatorColor(int indicatorColor) {
501 | this.indicatorColor = indicatorColor;
502 | invalidate();
503 | }
504 |
505 | public void setIndicatorColorResource(int resId) {
506 | this.indicatorColor = getResources().getColor(resId);
507 | invalidate();
508 | }
509 |
510 | public int getIndicatorColor() {
511 | return this.indicatorColor;
512 | }
513 |
514 | public void setIndicatorHeight(int indicatorLineHeightPx) {
515 | this.indicatorHeight = indicatorLineHeightPx;
516 | invalidate();
517 | }
518 |
519 | public int getIndicatorHeight() {
520 | return indicatorHeight;
521 | }
522 |
523 | public void setUnderlineColor(int underlineColor) {
524 | this.underlineColor = underlineColor;
525 | invalidate();
526 | }
527 |
528 | public void setUnderlineColorResource(int resId) {
529 | this.underlineColor = getResources().getColor(resId);
530 | invalidate();
531 | }
532 |
533 | public int getUnderlineColor() {
534 | return underlineColor;
535 | }
536 |
537 | public void setDividerColor(int dividerColor) {
538 | this.dividerColor = dividerColor;
539 | invalidate();
540 | }
541 |
542 | public void setDividerColorResource(int resId) {
543 | this.dividerColor = getResources().getColor(resId);
544 | invalidate();
545 | }
546 |
547 | public int getDividerColor() {
548 | return dividerColor;
549 | }
550 |
551 | public void setUnderlineHeight(int underlineHeightPx) {
552 | this.underlineHeight = underlineHeightPx;
553 | invalidate();
554 | }
555 |
556 | public int getUnderlineHeight() {
557 | return underlineHeight;
558 | }
559 |
560 | public void setDividerPadding(int dividerPaddingPx) {
561 | this.dividerPadding = dividerPaddingPx;
562 | invalidate();
563 | }
564 |
565 | public int getDividerPadding() {
566 | return dividerPadding;
567 | }
568 |
569 | public void setScrollOffset(int scrollOffsetPx) {
570 | this.scrollOffset = scrollOffsetPx;
571 | invalidate();
572 | }
573 |
574 | public int getScrollOffset() {
575 | return scrollOffset;
576 | }
577 |
578 | public void setSameLine(boolean sameLine) {
579 | this.isSameLine = sameLine;
580 | requestLayout();
581 | }
582 |
583 | public boolean getSameLine() {
584 | return isSameLine;
585 | }
586 |
587 | public boolean isTextAllCaps() {
588 | return textAllCaps;
589 | }
590 |
591 | public void setAllCaps(boolean textAllCaps) {
592 | this.textAllCaps = textAllCaps;
593 | }
594 |
595 | public void setTextSize(int textSizePx) {
596 | this.tabTextSize = textSizePx;
597 | updateTabStyles();
598 | }
599 |
600 | public int getTextSize() {
601 | return tabTextSize;
602 | }
603 |
604 | public void setTextColor(int textColor) {
605 | this.tabTextColor = textColor;
606 | updateTabStyles();
607 | }
608 |
609 | public void setTextColorSelected(int textColorSelected) {
610 | this.tabTextColorSelected = textColorSelected;
611 | updateTabStyles();
612 | }
613 |
614 | public void setTextColorResource(int resId) {
615 | this.tabTextColor = getResources().getColor(resId);
616 | updateTabStyles();
617 | }
618 |
619 | public int getTextColor() {
620 | return tabTextColor;
621 | }
622 |
623 | public void setTabBackground(int resId) {
624 | this.tabBackgroundResId = resId;
625 | updateTabStyles();
626 | }
627 |
628 | public int getTabBackground() {
629 | return tabBackgroundResId;
630 | }
631 |
632 | public void setTabPaddingLeftRight(int paddingPx) {
633 | this.tabPadding = paddingPx;
634 | updateTabStyles();
635 | }
636 |
637 | public int getTabPaddingLeftRight() {
638 | return tabPadding;
639 | }
640 |
641 | public int getIndicatorPaddingLeft() {
642 | return indicatorPaddingLeft;
643 | }
644 |
645 | public void setIndicatorPaddingLeft(int indicatorPaddingLeft) {
646 | this.indicatorPaddingLeft = indicatorPaddingLeft;
647 | }
648 |
649 | public int getIndicatorPaddingRight() {
650 | return indicatorPaddingRight;
651 | }
652 |
653 | public void setIndicatorPaddingRight(int indicatorPaddingRight) {
654 | this.indicatorPaddingRight = indicatorPaddingRight;
655 | }
656 |
657 | @Override
658 | public void onRestoreInstanceState(Parcelable state) {
659 | SavedState savedState = (SavedState) state;
660 | super.onRestoreInstanceState(savedState.getSuperState());
661 | currentPosition = savedState.currentPosition;
662 | requestLayout();
663 | }
664 |
665 | @Override
666 | public Parcelable onSaveInstanceState() {
667 | Parcelable superState = super.onSaveInstanceState();
668 | SavedState savedState = new SavedState(superState);
669 | savedState.currentPosition = currentPosition;
670 | return savedState;
671 | }
672 |
673 | static class SavedState extends BaseSavedState {
674 | int currentPosition;
675 |
676 | public SavedState(Parcelable superState) {
677 | super(superState);
678 | }
679 |
680 | private SavedState(Parcel in) {
681 | super(in);
682 | currentPosition = in.readInt();
683 | }
684 |
685 | @Override
686 | public void writeToParcel(Parcel dest, int flags) {
687 | super.writeToParcel(dest, flags);
688 | dest.writeInt(currentPosition);
689 | }
690 |
691 | public static final Creator CREATOR = new Creator() {
692 | @Override
693 | public SavedState createFromParcel(Parcel in) {
694 | return new SavedState(in);
695 | }
696 |
697 | @Override
698 | public SavedState[] newArray(int size) {
699 | return new SavedState[size];
700 | }
701 | };
702 | }
703 |
704 | /**
705 | * dip转化成px
706 | */
707 | public int dip2px(float dpValue) {
708 | float scale = mContext.getResources().getDisplayMetrics().density;
709 | return (int) (dpValue * scale + 0.5f);
710 | }
711 | }
712 |
--------------------------------------------------------------------------------
/tabpagerindictor/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/tabpagerindictor/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TabPagerIndictor
3 |
4 |
--------------------------------------------------------------------------------
/tabpagerindictor/src/test/java/shanyao/tabpagerindictor/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package shanyao.tabpagerindictor;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------