├── .gitignore
├── .idea
├── .name
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── dictionaries
│ └── Administrator.xml
├── gradle.xml
├── jarRepositories.xml
├── misc.xml
├── qaplug_profiles.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── README_EN.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── loper7
│ │ └── tablayout_ext
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── fonts
│ │ │ ├── Alibaba-PuHuiTi-Bold.ttf
│ │ │ ├── Alibaba-PuHuiTi-Medium.ttf
│ │ │ └── Alibaba-PuHuiTi-Regular.ttf
│ ├── java
│ │ └── com
│ │ │ └── loper7
│ │ │ └── tablayout_ext
│ │ │ ├── MainActivity.kt
│ │ │ ├── SimpleFragment.kt
│ │ │ ├── adapter
│ │ │ ├── CustomFragmentAdapter.kt
│ │ │ ├── MainFragmentAdapter.kt
│ │ │ └── SimpleFragmentAdapter.kt
│ │ │ ├── fragment
│ │ │ ├── CustomIndicatorFragment.kt
│ │ │ ├── LinearIndicatorFragment.kt
│ │ │ └── TriangleIndicatorFragment.kt
│ │ │ └── helper
│ │ │ └── StatusBarHelper.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_linear_indicator.xml
│ │ ├── fragment_other_indicator.xml
│ │ ├── fragment_simple.xml
│ │ └── fragment_triangle_indicator.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_indicator_finger.png
│ │ ├── ic_indicator_fire.png
│ │ ├── ic_indicator_index.png
│ │ ├── ic_indicator_t.png
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── loper7
│ └── tablayout_ext
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── image
├── demo_gif.gif
└── logo.png
├── settings.gradle
└── tablayout-expand
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── loper7
│ └── tab_expand
│ └── ExampleInstrumentedTest.kt
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── loper7
│ │ └── tab_expand
│ │ ├── ext
│ │ ├── CommonExt.kt
│ │ └── TabLayoutExt.kt
│ │ ├── indicator
│ │ ├── BaseIndicator.kt
│ │ ├── CustomIndicator.kt
│ │ ├── LinearIndicator.kt
│ │ └── TriangleIndicator.kt
│ │ └── text
│ │ └── BaseText.kt
└── res
│ └── drawable
│ ├── tab_indicator_triangle_f.xml
│ └── tab_indicator_triangle_z.xml
└── test
└── java
└── com
└── loper7
└── tab_expand
└── ExampleUnitTest.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | tablayout-ext-simple
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/dictionaries/Administrator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.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 |
--------------------------------------------------------------------------------
/.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 | Android API 15 Platform
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/.idea/qaplug_profiles.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 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
--------------------------------------------------------------------------------
/.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 | 
2 |
3 | [](https://jitpack.io/#loperSeven/DateTimePicker) [](https://android-arsenal.com/api?level=21) [](https://github.com/loperSeven) [](https://opensource.org/licenses/MIT)
4 |
5 | ## Language
6 | 中文 | [English](https://github.com/loperSeven/tablayout-ext/blob/master/README_EN.md)
7 |
8 |
9 | google 原生 Tablayout( com.google.android.material.tabs.TabLayout) 零入侵拓展,帮你更便捷的使用原生TabLayout实现一些UI效果
10 |
11 | ## 预览
12 | 
13 |
14 | 无法加载可前往 [简书](https://www.jianshu.com/p/63fe08bd67da) 或 [掘金](https://juejin.cn/post/6904468604419473422)查看
15 | ## 如何引入
16 | Step 1. 添加 JitPack repository
17 | ```
18 | allprojects {
19 | repositories {
20 | ...
21 | maven { url "https://jitpack.io" }
22 | }
23 | }
24 | ```
25 | Step 2. 添加 Gradle依赖
26 | ```
27 | dependencies {
28 | ...
29 | implementation 'com.google.android.material:material:1.2.1'//google material 包
30 | implementation 'com.github.loperSeven:tablayout-ext:0.1.3'// 最新版本请看顶部jitpack标识,仅支持androidx
31 | }
32 |
33 |
34 | ```
35 | ## 如何使用
36 | 注意:此库只是针对Tablayout做一些便捷性拓展,具体Tablayout属性及用法请查阅:[developers 文档](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout)
37 | #### Indicator
38 | ```kotlin
39 | /**
40 | * 线性指示器
41 | * buildIndicator<> 指定指示器类
42 | * setHeight() 设置指示器高度,默认为tablayout指定tabIndicatorHeight高度
43 | * setWidth() 设置指示器宽度,若tablayout设置了tabIndicatorFullWidth=true,则默认为tab项宽度,否则为tab实际文字宽度
44 | * setGravity() 等同于 Tablayout.setSelectedTabIndicatorGravity()
45 | * setColor() 等同于 Tablayout.setSelectedTabIndicatorColor()
46 | */
47 | tabLayout.buildIndicator()
48 | .setHeight(22.toPx())
49 | .setWidth(BaseIndicator.MATCH)
50 | .setGravity(TabLayout.INDICATOR_GRAVITY_TOP)
51 | .setColor(ContextCompat.getColor(context!!,R.color.colorAccent))
52 | .bind()
53 | /**
54 | * 三角形指示器
55 | * buildIndicator<> 指定指示器类
56 | * setPath 设置三角形样式 [POSITIVE]正 [NEGATIVE] 反
57 | */
58 | tabLayout.buildIndicator()
59 | .setPath(TriangleIndicator.Path.NEGATIVE)//因path为该指示器专有属性,故需先于其他属性调用。
60 | .setWidth(10.toPx())
61 | .setHeight(10.toPx())
62 | .setColor(ContextCompat.getColor(context!!,R.color.colorAccent))
63 | .setGravity(TabLayout.INDICATOR_GRAVITY_TOP)
64 | .bind()
65 |
66 | /**
67 | * 自定义deawable指示器
68 | * buildIndicator<> 指定指示器类
69 | * setDrawable 设置指示器drawable 可传入 Drawable 或 @DrawableRes resId:Int
70 | * 其他属性同上,皆为基础属性
71 | */
72 | tabLayout.buildIndicator()
73 | .setDrawable(ContextCompat.getDrawable(context!!,R.mipmap.ic_indicator_fire)!!)
74 | .bind()
75 |
76 | ```
77 | 如需拓展更多类型指示器,只需继承自BaseIndicator,添加专属属性,在bind()方法中实现逻辑即可。
78 | #### Text
79 | ```kotlin
80 | /**
81 | * tab文字设置
82 | * buildText<> 指定文字设置类
83 | * setNormalTextBold() 未选中状态下文字是否加粗 默认false
84 | * setSelectTextBold() 选中状态下文字是否加粗 默认true
85 | * setNormalTextSize() 未选中状态下文字大小 默认14f(单位sp)
86 | * setSelectTextSize() 选中状态下文字大小 默认14f(单位sp)
87 | */
88 | tabLayout.buildText()
89 | .setNormalTextBold(true)
90 | .setSelectTextBold(true)
91 | .setNormalTextSize(16f)
92 | .setSelectTextSize(18f)
93 | .bind()
94 | ```
95 |
96 |
97 | ## 更新计划
98 | * Indicator 动画拓展
99 | * ~~Text 文字大小设置~~
100 |
101 | 您的star是我更新的动力
102 |
103 | ## 混淆
104 | ```
105 | -dontwarn com.loper7.tablayout-ext.**
106 | -keep class com.loper7.tablayout-ext.**{*;}
107 | ```
108 |
109 | ## 联系我
110 | Issues:[Issues](https://github.com/loperSeven/tablayout-ext/issues)
111 |
112 | 邮箱:loper7@163.com
113 |
114 | ## Licenses
115 | ```
116 | Copyright 2020 loperSeven
117 |
118 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
119 |
120 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
121 |
122 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
123 | ```
124 |
125 |
126 |
--------------------------------------------------------------------------------
/README_EN.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [](https://jitpack.io/#loperSeven/DateTimePicker) [](https://android-arsenal.com/api?level=21) [](https://github.com/loperSeven) [](https://opensource.org/licenses/MIT)
4 |
5 | ## Language
6 | [中文](https://github.com/loperSeven/tablayout-ext) | English
7 |
8 |
9 | The Zero invasion expansion of com.google.android.material.tabs.TabLayout, allows you to use TabLayout to achieve UI effects more conveniently
10 |
11 | ## Preview
12 | 
13 |
14 | ## Import
15 | Step 1. add JitPack repository
16 | ```
17 | allprojects {
18 | repositories {
19 | ...
20 | maven { url "https://jitpack.io" }
21 | }
22 | }
23 | ```
24 | Step 2. add Gradle
25 | ```
26 | dependencies {
27 | ...
28 | implementation 'com.google.android.material:material:1.2.1'//google material package
29 | implementation 'com.github.loperSeven:tablayout-ext:$version'//see the jitpack logo at the top for the specific version, only supports androidx
30 | }
31 |
32 |
33 | ```
34 | ## Use
35 | Note: This library is only for some convenience expansions for Tablayout, please refer to the specific Tablayout attributes and usage:[developers wiki](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout)
36 | #### Indicator
37 | ```kotlin
38 | /**
39 | * setHeight() Set indicator height
40 | * setWidth() Set indicator width
41 | * setGravity() = Tablayout.setSelectedTabIndicatorGravity()
42 | * setColor() = Tablayout.setSelectedTabIndicatorColor()
43 | */
44 | tabLayout.buildIndicator()
45 | .setHeight(22.toPx())
46 | .setWidth(BaseIndicator.MATCH)
47 | .setGravity(TabLayout.INDICATOR_GRAVITY_TOP)
48 | .setColor(ContextCompat.getColor(context!!,R.color.colorAccent))
49 | .bind()
50 | /**
51 | * setPath [POSITIVE] or [NEGATIVE]
52 | */
53 | tabLayout.buildIndicator()
54 | .setPath(TriangleIndicator.Path.NEGATIVE)
55 | .setWidth(10.toPx())
56 | .setHeight(10.toPx())
57 | .setColor(ContextCompat.getColor(context!!,R.color.colorAccent))
58 | .setGravity(TabLayout.INDICATOR_GRAVITY_TOP)
59 | .bind()
60 |
61 | /**
62 | * setDrawable set Drawable or @DrawableRes resId:Int
63 | * Same as above
64 | */
65 | tabLayout.buildIndicator()
66 | .setDrawable(ContextCompat.getDrawable(context!!,R.mipmap.ic_indicator_fire)!!)
67 | .bind()
68 |
69 | ```
70 | If you need to expand more type indicators, you only need to inherit from BaseIndicator, add exclusive attributes, and implement logic in the bind() method.
71 | #### Text
72 | ```kotlin
73 | tabLayout.buildText()
74 | .setNormalTextBold(true)
75 | .setSelectTextBold(true)
76 | .setNormalTextSize(16f)
77 | .setSelectTextSize(18f)
78 | .bind()
79 | ```
80 |
81 | ## ignore
82 | ```
83 | -dontwarn com.loper7.tablayout-ext.**
84 | -keep class com.loper7.tablayout-ext.**{*;}
85 | ```
86 |
87 | ## contact me
88 | Issues:[Issues](https://github.com/loperSeven/tablayout-ext/issues)
89 |
90 | Email:loper7ins@gmail.com
91 |
92 | ## Licenses
93 | ```
94 | Copyright 2020 loperSeven
95 |
96 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
97 |
98 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
99 |
100 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
101 | ```
102 |
103 |
104 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.loper7.tablayout_ext"
11 | minSdkVersion 23
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation 'androidx.core:core-ktx:1.3.1'
33 | implementation "com.google.android.material:material:1.2.1"
34 |
35 | implementation project(path: ':tablayout-expand')
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/loper7/tablayout_ext/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.loper7.tablayout_ext", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/Alibaba-PuHuiTi-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/assets/fonts/Alibaba-PuHuiTi-Bold.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/Alibaba-PuHuiTi-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/assets/fonts/Alibaba-PuHuiTi-Medium.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/Alibaba-PuHuiTi-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/assets/fonts/Alibaba-PuHuiTi-Regular.ttf
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import com.google.android.material.tabs.TabLayout
6 | import com.loper7.tablayout_ext.adapter.MainFragmentAdapter
7 | import com.loper7.tablayout_ext.helper.StatusBarHelper
8 | import com.loper7.tab_expand.ext.buildIndicator
9 | import com.loper7.tab_expand.ext.buildText
10 | import com.loper7.tab_expand.ext.toPx
11 | import com.loper7.tab_expand.indicator.LinearIndicator
12 | import com.loper7.tab_expand.text.BaseText
13 | import kotlinx.android.synthetic.main.activity_main.*
14 |
15 | class MainActivity : AppCompatActivity() {
16 |
17 | private lateinit var adapter:MainFragmentAdapter
18 |
19 | override fun onCreate(savedInstanceState: Bundle?) {
20 | super.onCreate(savedInstanceState)
21 | setContentView(R.layout.activity_main)
22 | StatusBarHelper.setDarkStatusIcon(this,true)
23 |
24 |
25 |
26 | adapter = MainFragmentAdapter(supportFragmentManager)
27 | viewPager.adapter = adapter
28 | viewPager.offscreenPageLimit = 3
29 | tabLayout.setupWithViewPager(viewPager)
30 |
31 | tabLayout.buildIndicator()
32 | .bind()
33 |
34 | tabLayout.buildText()
35 | .setNormalTextBold(true)
36 | .setSelectTextSize(15f)
37 | .setSelectTextBold(true).bind()
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/SimpleFragment.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import kotlinx.android.synthetic.main.fragment_simple.*
9 |
10 | /**
11 | *
12 | * @CreateDate: 2020/7/28 11:34
13 | * @Description: java类作用描述
14 | * @Author: LOPER7
15 | * @Email: loper7@163.com
16 | */
17 | class SimpleFragment :Fragment() {
18 | var mRootView: View? = null
19 |
20 | companion object {
21 | fun newInstance(text: String): SimpleFragment {
22 | val args = Bundle()
23 | args.putString("text", text)
24 | val fragment = SimpleFragment()
25 | fragment.arguments = args
26 | return fragment
27 | }
28 | }
29 |
30 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
31 | if (mRootView == null) {
32 | mRootView = View.inflate(context, R.layout.fragment_simple, null)
33 | }
34 | return mRootView
35 | }
36 |
37 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
38 | super.onViewCreated(view, savedInstanceState)
39 | tv_text.text = requireArguments().getString("text")
40 | }
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/adapter/CustomFragmentAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.adapter
2 |
3 | import androidx.fragment.app.*
4 | import com.loper7.tablayout_ext.SimpleFragment
5 |
6 | /**
7 | *
8 | * @CreateDate: 2020/6/12 11:15
9 | * @Description: java类作用描述
10 | * @Author: LOPER7
11 | * @Email: loper7@163.com
12 | */
13 | class CustomFragmentAdapter(fm:FragmentManager) : FragmentStatePagerAdapter(fm) {
14 |
15 | override fun getCount(): Int {
16 | return 6
17 | }
18 |
19 | override fun getItem(position: Int): Fragment {
20 | return SimpleFragment.newInstance("PAGE $position")
21 | }
22 |
23 | override fun getPageTitle(position: Int): CharSequence? {
24 | return when(position){
25 | 0-> "直播"
26 | 1-> "推荐"
27 | 2-> "热门"
28 | 3-> "追番"
29 | 4-> "抗击肺炎"
30 | 5-> "总之就是非常可爱"
31 | else-> "PHP"
32 | }
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/adapter/MainFragmentAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.adapter
2 |
3 | import androidx.fragment.app.*
4 | import com.loper7.tablayout_ext.fragment.LinearIndicatorFragment
5 | import com.loper7.tablayout_ext.fragment.CustomIndicatorFragment
6 | import com.loper7.tablayout_ext.fragment.TriangleIndicatorFragment
7 |
8 | /**
9 | *
10 | * @CreateDate: 2020/6/12 11:15
11 | * @Description: java类作用描述
12 | * @Author: LOPER7
13 | * @Email: loper7@163.com
14 | */
15 | class MainFragmentAdapter(fm:FragmentManager) : FragmentStatePagerAdapter(fm) {
16 |
17 | override fun getCount(): Int {
18 | return 3
19 | }
20 |
21 | override fun getItem(position: Int): Fragment {
22 | return when(position){
23 | 0->LinearIndicatorFragment()
24 | 1-> TriangleIndicatorFragment()
25 | else->CustomIndicatorFragment()
26 | }
27 | }
28 |
29 | override fun getPageTitle(position: Int): CharSequence? {
30 | return when(position){
31 | 0-> "LINEAR"
32 | 1-> "TRIANGLE"
33 | 2-> "CUSTOM"
34 | else->""
35 | }
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/adapter/SimpleFragmentAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.adapter
2 |
3 | import androidx.fragment.app.*
4 | import com.loper7.tablayout_ext.SimpleFragment
5 |
6 | /**
7 | *
8 | * @CreateDate: 2020/6/12 11:15
9 | * @Description: java类作用描述
10 | * @Author: LOPER7
11 | * @Email: loper7@163.com
12 | */
13 | class SimpleFragmentAdapter(fm:FragmentManager) : FragmentStatePagerAdapter(fm) {
14 |
15 | override fun getCount(): Int {
16 | return 6
17 | }
18 |
19 | override fun getItem(position: Int): Fragment {
20 | return SimpleFragment.newInstance("PAGE $position")
21 | }
22 |
23 | override fun getPageTitle(position: Int): CharSequence? {
24 | return when(position){
25 | 0-> "JAVA"
26 | 1-> "OBJECT-C"
27 | 2-> "FLUTTER"
28 | 3-> "KOTLIN"
29 | 4-> "SWIFT"
30 | 5-> "REACT NATIVE"
31 | else-> "PHP"
32 | }
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/fragment/CustomIndicatorFragment.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.fragment
2 |
3 | import android.graphics.drawable.ColorDrawable
4 | import android.graphics.drawable.Drawable
5 | import android.os.Build
6 | import android.os.Bundle
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 | import androidx.annotation.RequiresApi
13 | import androidx.core.content.ContextCompat
14 | import androidx.fragment.app.Fragment
15 | import com.google.android.material.tabs.TabLayout
16 | import com.loper7.tab_expand.ext.buildIndicator
17 | import com.loper7.tab_expand.ext.buildText
18 | import com.loper7.tab_expand.ext.toPx
19 | import com.loper7.tab_expand.indicator.BaseIndicator
20 | import com.loper7.tab_expand.indicator.CustomIndicator
21 | import com.loper7.tab_expand.indicator.TriangleIndicator
22 | import com.loper7.tab_expand.text.BaseText
23 | import com.loper7.tablayout_ext.R
24 | import com.loper7.tablayout_ext.adapter.CustomFragmentAdapter
25 | import com.loper7.tablayout_ext.adapter.SimpleFragmentAdapter
26 | import kotlinx.android.synthetic.main.fragment_other_indicator.*
27 | import kotlinx.android.synthetic.main.fragment_other_indicator.tabLayout
28 | import kotlinx.android.synthetic.main.fragment_other_indicator.tabLayout1
29 | import kotlinx.android.synthetic.main.fragment_other_indicator.tabLayout2
30 | import kotlinx.android.synthetic.main.fragment_other_indicator.tabLayout3
31 | import kotlinx.android.synthetic.main.fragment_other_indicator.viewPager
32 |
33 | /**
34 | *
35 | * @CreateDate: 2020/7/28 11:34
36 | * @Description: OtherIndicatorFragment
37 | * @Author: LOPER7
38 | * @Email: loper7@163.com
39 | */
40 | class CustomIndicatorFragment : Fragment() {
41 | var mRootView: View? = null
42 | private lateinit var adapter: CustomFragmentAdapter
43 |
44 | override fun onCreateView(
45 | inflater: LayoutInflater,
46 | container: ViewGroup?,
47 | savedInstanceState: Bundle?
48 | ): View? {
49 | if (mRootView == null) {
50 | mRootView = View.inflate(context, R.layout.fragment_other_indicator, null)
51 | }
52 | return mRootView
53 | }
54 |
55 | @RequiresApi(Build.VERSION_CODES.M)
56 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
57 | super.onViewCreated(view, savedInstanceState)
58 |
59 | adapter = CustomFragmentAdapter(childFragmentManager)
60 | viewPager.adapter = adapter
61 | tabLayout.setupWithViewPager(viewPager)
62 | tabLayout1.setupWithViewPager(viewPager)
63 | tabLayout2.setupWithViewPager(viewPager)
64 | tabLayout3.setupWithViewPager(viewPager)
65 | tabLayout4.setupWithViewPager(viewPager)
66 |
67 |
68 |
69 |
70 | // custom1
71 | tabLayout.buildIndicator()
72 | .setDrawable(ContextCompat.getDrawable(context!!, R.mipmap.ic_indicator_fire)!!)
73 | .setWidth(15.toPx())
74 | .setHeight(15.toPx())
75 | .bind()
76 | tabLayout.buildText()
77 | .setNormalTextBold(false)
78 | .setSelectTextBold(true)
79 | .setNormalTextSize(16f)
80 | .setSelectTextSize(18f)
81 | .bind()
82 | // custom2
83 | tabLayout1.buildIndicator()
84 | .setDrawable(ContextCompat.getDrawable(context!!, R.mipmap.ic_indicator_t)!!)
85 | .setWidth(BaseIndicator.MATCH)
86 | .setHeight(BaseIndicator.MATCH)
87 | .bind()
88 | tabLayout1.buildText()
89 | .setNormalTextBold(false)
90 | .setSelectTextBold(true)
91 | .bind()
92 | // custom3
93 | tabLayout2.buildIndicator()
94 | .setDrawable(ContextCompat.getDrawable(context!!, R.mipmap.ic_indicator_finger)!!)
95 | .setWidth(15.toPx())
96 | .setHeight(15.toPx())
97 | .bind()
98 | tabLayout2.buildText()
99 | .setNormalTextBold(false)
100 | .setSelectTextBold(true)
101 | .bind()
102 | // custom4
103 | tabLayout3.buildIndicator()
104 | .setDrawable(ContextCompat.getDrawable(context!!, R.mipmap.ic_indicator_index)!!)
105 | .setHeight(8.toPx())
106 | .setWidth(50.toPx())
107 | .bind()
108 | tabLayout3.buildText()
109 | .setNormalTextBold(false)
110 | .setSelectTextBold(true)
111 | .bind()
112 | //custom5
113 | tabLayout4.buildIndicator()
114 | .setDrawable(ColorDrawable(ContextCompat.getColor(context!!, R.color.colorAccent)))
115 | .setHeight(BaseIndicator.MATCH)
116 | .setWidth(BaseIndicator.MATCH)
117 | .bind()
118 | tabLayout4.buildText()
119 | .setNormalTextBold(false)
120 | .setSelectTextBold(true)
121 | .bind()
122 |
123 | }
124 |
125 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/fragment/LinearIndicatorFragment.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.fragment
2 |
3 | import android.graphics.Color
4 | import android.os.Build
5 | import android.os.Bundle
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import androidx.annotation.RequiresApi
10 | import androidx.fragment.app.Fragment
11 | import com.google.android.material.tabs.TabLayout
12 | import com.loper7.tab_expand.ext.buildIndicator
13 | import com.loper7.tab_expand.ext.buildText
14 | import com.loper7.tab_expand.ext.toPx
15 | import com.loper7.tab_expand.indicator.BaseIndicator
16 | import com.loper7.tablayout_ext.adapter.SimpleFragmentAdapter
17 | import com.loper7.tab_expand.indicator.LinearIndicator
18 | import com.loper7.tab_expand.text.BaseText
19 | import com.loper7.tablayout_ext.R
20 | import com.loper7.tablayout_ext.adapter.CustomFragmentAdapter
21 | import kotlinx.android.synthetic.main.fragment_linear_indicator.*
22 | import kotlinx.android.synthetic.main.fragment_linear_indicator.tabLayout
23 | import kotlinx.android.synthetic.main.fragment_linear_indicator.tabLayout1
24 | import kotlinx.android.synthetic.main.fragment_linear_indicator.tabLayout2
25 | import kotlinx.android.synthetic.main.fragment_linear_indicator.tabLayout3
26 | import kotlinx.android.synthetic.main.fragment_linear_indicator.viewPager
27 |
28 | /**
29 | *
30 | * @CreateDate: 2020/7/28 11:34
31 | * @Description: java类作用描述
32 | * @Author: LOPER7
33 | * @Email: loper7@163.com
34 | */
35 | class LinearIndicatorFragment :Fragment() {
36 | var mRootView: View? = null
37 | private lateinit var adapter: SimpleFragmentAdapter
38 |
39 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
40 | if (mRootView == null) {
41 | mRootView = View.inflate(context,
42 | R.layout.fragment_linear_indicator, null)
43 | }
44 | return mRootView
45 | }
46 |
47 | @RequiresApi(Build.VERSION_CODES.M)
48 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
49 | super.onViewCreated(view, savedInstanceState)
50 |
51 | adapter = SimpleFragmentAdapter(childFragmentManager)
52 | viewPager.adapter = adapter
53 | tabLayout_default.setupWithViewPager(viewPager)
54 | tabLayout.setupWithViewPager(viewPager)
55 | tabLayout1.setupWithViewPager(viewPager)
56 | tabLayout2.setupWithViewPager(viewPager)
57 | tabLayout3.setupWithViewPager(viewPager)
58 | tabLayout4.setupWithViewPager(viewPager)
59 |
60 |
61 | // tabLayout_default.buildText()
62 | // .setNormalTextBold(false)
63 | // .setSelectTextBold(true)
64 | // .setNormalTextSize(16f)
65 | // .setSelectTextSize(18f)
66 | // .bind()
67 | // LinearIndicator
68 | tabLayout.buildIndicator().bind()
69 | tabLayout.buildText()
70 | .setNormalTextBold(false)
71 | .setSelectTextBold(true)
72 | .setNormalTextSize(16f)
73 | .setSelectTextSize(18f)
74 | .bind()
75 | // LinearIndicator (w=35,h=3.5)
76 | tabLayout1.buildIndicator()
77 | .setWidth(35.toPx())
78 | .setHeight(4.toPx())
79 | .bind()
80 | tabLayout1.buildText()
81 | .setNormalTextBold(false)
82 | .setSelectTextBold(true)
83 | .bind()
84 | // LinearIndicator (w=5,h=5)
85 | tabLayout2.buildIndicator()
86 | .setWidth(5.toPx())
87 | .setHeight(5.toPx())
88 | .bind()
89 | tabLayout2.buildText()
90 | .setNormalTextBold(false)
91 | .setSelectTextBold(true)
92 | .bind()
93 | // LinearIndicator (w=auto,h=match,a=4)
94 | tabLayout3.buildIndicator()
95 | .setAngle(4.toPx())
96 | .setHeight(BaseIndicator.MATCH)
97 | .setWidth(BaseIndicator.MATCH)
98 | .bind()
99 | tabLayout3.buildText()
100 | .setNormalTextBold(true)
101 | .setSelectTextBold(true)
102 | .bind()
103 | // LinearIndicator (w=auto,h=22,a=auto)
104 | tabLayout4.buildIndicator()
105 | .setHeight(22.toPx())
106 | .bind()
107 |
108 | tabLayout4.buildText()
109 | .setNormalTextBold(true)
110 | .setSelectTextBold(true)
111 | .bind()
112 |
113 | tabLayout.getTabAt(1)?.orCreateBadge?.backgroundColor=Color.parseColor("#FF9900")
114 | tabLayout.getTabAt(1)?.orCreateBadge?.number=6
115 |
116 | }
117 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/fragment/TriangleIndicatorFragment.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.fragment
2 |
3 | import android.os.Build
4 | import android.os.Bundle
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import androidx.annotation.RequiresApi
9 | import androidx.core.content.ContextCompat
10 | import androidx.fragment.app.Fragment
11 | import com.google.android.material.tabs.TabLayout
12 | import com.loper7.tab_expand.ext.buildIndicator
13 | import com.loper7.tab_expand.ext.toPx
14 | import com.loper7.tab_expand.indicator.TriangleIndicator
15 | import com.loper7.tablayout_ext.R
16 | import com.loper7.tablayout_ext.adapter.SimpleFragmentAdapter
17 | import kotlinx.android.synthetic.main.fragment_triangle_indicator.*
18 |
19 | /**
20 | *
21 | * @CreateDate: 2020/7/28 11:34
22 | * @Description: java类作用描述
23 | * @Author: LOPER7
24 | * @Email: loper7@163.com
25 | */
26 | class TriangleIndicatorFragment :Fragment() {
27 | var mRootView: View? = null
28 | private lateinit var adapter: SimpleFragmentAdapter
29 |
30 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
31 | if (mRootView == null) {
32 | mRootView = View.inflate(context, R.layout.fragment_triangle_indicator, null)
33 | }
34 | return mRootView
35 | }
36 |
37 | @RequiresApi(Build.VERSION_CODES.M)
38 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39 | super.onViewCreated(view, savedInstanceState)
40 |
41 | adapter = SimpleFragmentAdapter(childFragmentManager)
42 | viewPager.adapter = adapter
43 | tabLayout.setupWithViewPager(viewPager)
44 | tabLayout1.setupWithViewPager(viewPager)
45 | tabLayout2.setupWithViewPager(viewPager)
46 |
47 |
48 | // TriangleIndicator
49 | tabLayout.buildIndicator().bind()
50 | // TriangleIndicator(p=NEGATIVE)
51 | tabLayout1.buildIndicator()
52 | .setPath(TriangleIndicator.Path.NEGATIVE)
53 | .bind()
54 | // TriangleIndicator(w=10,h=10,p=NEGATIVE,g=top)
55 | tabLayout2.buildIndicator()
56 | .setPath(TriangleIndicator.Path.NEGATIVE)
57 | .setWidth(10.toPx())
58 | .setHeight(10.toPx())
59 | .setColor(ContextCompat.getColor(context!!,R.color.colorAccent))
60 | .setGravity(TabLayout.INDICATOR_GRAVITY_TOP)
61 | .bind()
62 |
63 | }
64 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/loper7/tablayout_ext/helper/StatusBarHelper.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext.helper
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import android.view.View
6 |
7 | /**
8 | * @CreateDate: 2020/7/28 10:32
9 | * @Description: 状态栏帮助类
10 | * @Author: LOPER7
11 | * @Email: loper7@163.com
12 | */
13 | object StatusBarHelper {
14 | /**
15 | * 是否使用深色状态栏
16 | *
17 | * @param bDark
18 | */
19 | fun setDarkStatusIcon(activity: Activity, bDark: Boolean) {
20 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
21 | val decorView = activity.window.decorView
22 | if (decorView != null) {
23 | var vis = decorView.systemUiVisibility
24 | vis = if (bDark) {
25 | vis or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
26 | } else {
27 | vis and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
28 | }
29 | decorView.systemUiVisibility = vis
30 | }
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
24 |
25 |
29 |
30 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_linear_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
17 |
18 |
34 |
35 |
44 |
60 |
69 |
83 |
92 |
106 |
114 |
129 |
137 |
152 |
153 |
157 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_other_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
31 |
40 |
54 |
63 |
76 |
85 |
98 |
107 |
119 |
120 |
124 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_simple.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_triangle_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
31 |
32 |
41 |
42 |
54 |
63 |
64 |
77 |
78 |
82 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_indicator_finger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxxhdpi/ic_indicator_finger.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_indicator_fire.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxxhdpi/ic_indicator_fire.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_indicator_index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxxhdpi/ic_indicator_index.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_indicator_t.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxxhdpi/ic_indicator_t.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 | #FFFFFF
5 | #58B87F
6 |
7 | #202124
8 | #60646B
9 | #919499
10 | #B8BABF
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TABLAYOUT-EXT
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/loper7/tablayout_ext/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tablayout_ext
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.4.0-rc'
5 | ext.kotlin_version = '1.3.61'
6 | repositories {
7 | google()
8 | jcenter()
9 | maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
10 |
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:3.6.1'
14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15 |
16 | // NOTE: Do not place your application dependencies here; they belong
17 | // in the individual module build.gradle files
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | google()
24 | jcenter()
25 | maven { url "https://jitpack.io" }
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 28 09:14:10 CST 2020
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-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/image/demo_gif.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/image/demo_gif.gif
--------------------------------------------------------------------------------
/image/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/image/logo.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='tablayout-ext-simple'
2 | include ':app'
3 | include ':tablayout-expand'
4 |
--------------------------------------------------------------------------------
/tablayout-expand/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tablayout-expand/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "30.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles 'consumer-rules.pro'
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | compileOnly "com.google.android.material:material:1.2.1"
31 | }
32 |
--------------------------------------------------------------------------------
/tablayout-expand/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/loper7/tablayout-ext/36cf40af7f6bd2752c870b7de0a4b7c133fddad9/tablayout-expand/consumer-rules.pro
--------------------------------------------------------------------------------
/tablayout-expand/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/tablayout-expand/src/androidTest/java/com/loper7/tab_expand/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.loper7.tab_expand.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tablayout-expand/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/ext/CommonExt.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.ext
2 |
3 | import android.content.Context
4 | import android.content.res.Resources
5 |
6 | /**
7 | *
8 | * @CreateDate: 2020/8/18 11:15
9 | * @Description: java类作用描述
10 | * @Author: LOPER7
11 | * @Email: loper7@163.com
12 | */
13 | fun Int.toDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()
14 | fun Int.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt()
15 | fun Double.toDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()
16 | fun Double.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt()
17 |
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/ext/TabLayoutExt.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.ext
2 |
3 | import android.widget.LinearLayout
4 | import android.widget.TextView
5 | import com.google.android.material.tabs.TabLayout
6 | import com.loper7.tab_expand.indicator.BaseIndicator
7 | import com.loper7.tab_expand.text.BaseText
8 |
9 | /**
10 | * 绑定tabLayout指示器
11 | */
12 | inline fun TabLayout.buildIndicator():T {
13 | val indicator = T::class.java.newInstance()
14 | indicator.bindTabLayout(this)
15 | return indicator
16 | }
17 |
18 | /**
19 | * 绑定tabLayout文字设置
20 | */
21 | inline fun TabLayout.buildText():T {
22 | val text = T::class.java.newInstance()
23 | text.bindTabLayout(this)
24 | return text
25 | }
26 |
27 |
28 |
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/indicator/BaseIndicator.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.indicator
2 |
3 | import android.R
4 | import android.content.Context
5 | import android.widget.LinearLayout
6 | import android.widget.TextView
7 | import androidx.annotation.ColorInt
8 | import androidx.annotation.Px
9 | import com.google.android.material.tabs.TabLayout
10 | import com.loper7.tab_expand.ext.toPx
11 |
12 |
13 | /**
14 | *
15 | * @CreateDate: 2020/8/5 9:50
16 | * @Description: java类作用描述
17 | * @Author: LOPER7
18 | * @Email: loper7@163.com
19 | */
20 | abstract class BaseIndicator {
21 | companion object{
22 | //填充满
23 | val MATCH = -1
24 | }
25 |
26 | protected var width: Int = 0
27 | protected var height: Int = 0
28 | protected var context: Context? = null
29 | protected var tabLayout: TabLayout? = null
30 |
31 | fun bindTabLayout(tabLayout: TabLayout) {
32 | this.tabLayout = tabLayout
33 | this.context = tabLayout.context
34 |
35 |
36 |
37 | }
38 |
39 | fun setColor(@ColorInt color: Int): BaseIndicator {
40 | tabLayout?.setSelectedTabIndicatorColor(color)
41 | return this
42 | }
43 |
44 | fun setWidth(@Px width: Int): BaseIndicator {
45 | this.width = width
46 | return this
47 | }
48 |
49 | fun setHeight(@Px height: Int): BaseIndicator {
50 | this.height = height
51 | return this
52 | }
53 |
54 | /**
55 | * Indicator gravity used to align the tab selection indicator to the bottom of the {@link
56 | * TabLayout}. This will only take effect if the indicator height is set via the custom indicator
57 | * drawable's intrinsic height (preferred), via the {@code tabIndicatorHeight} attribute
58 | * (deprecated), or via {@link #setSelectedTabIndicatorHeight(int)} (deprecated). Otherwise, the
59 | * indicator will not be shown. This is the default value.
60 | *
61 | * @see #setSelectedTabIndicatorGravity(int)
62 | * @see #getTabIndicatorGravity()
63 | * @attr ref com.google.android.material.R.styleable#TabLayout_tabIndicatorGravity
64 | */
65 | fun setGravity(gravity: Int): BaseIndicator {
66 | tabLayout?.setSelectedTabIndicatorGravity(gravity)
67 | return this
68 | }
69 |
70 | abstract fun bind()
71 | }
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/indicator/CustomIndicator.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.indicator
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.graphics.Bitmap
6 | import android.graphics.drawable.*
7 | import android.os.Build
8 | import android.view.Gravity
9 | import android.view.View
10 | import androidx.annotation.DrawableRes
11 | import androidx.annotation.RequiresApi
12 | import androidx.core.content.ContextCompat
13 | import com.google.android.material.tabs.TabLayout
14 | import com.loper7.tab_expand.R
15 | import com.loper7.tab_expand.ext.toPx
16 |
17 |
18 | /**
19 | *
20 | * @CreateDate: 2020/8/4 17:36
21 | * @Description: CustomIndicator 自定义
22 | * @Author: LOPER7
23 | * @Email: loper7@163.com
24 | */
25 | open class CustomIndicator : BaseIndicator() {
26 |
27 | protected var drawable: Drawable? = null
28 |
29 | fun setDrawable(drawable: Drawable): CustomIndicator {
30 | this.drawable = drawable
31 | return this
32 | }
33 |
34 | fun setDrawable(@DrawableRes resId:Int):CustomIndicator{
35 | this.drawable = ContextCompat.getDrawable(context!!,resId)
36 | return this
37 | }
38 |
39 | override fun bind() {
40 | tabLayout?.post {
41 |
42 | if(height==MATCH)
43 | height = tabLayout?.height!!
44 |
45 | val layerDrawable = LayerDrawable(arrayOf(drawable))
46 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
47 | layerDrawable.setLayerHeight(0, height)
48 | layerDrawable.setLayerWidth(0, width)
49 | layerDrawable.setLayerGravity(0, Gravity.CENTER)
50 | }
51 |
52 | if (width == 0 && height == 0)
53 | tabLayout?.setSelectedTabIndicator(drawable)
54 | else
55 | tabLayout?.setSelectedTabIndicator(layerDrawable)
56 |
57 |
58 | if (height == 0)
59 | tabLayout?.setSelectedTabIndicatorHeight(3.toPx())
60 | else
61 | tabLayout?.setSelectedTabIndicatorHeight(height)
62 |
63 | //对自适应宽度进行处理
64 | if (width <= 0 && tabLayout?.tabSelectedIndicator is LayerDrawable) {
65 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
66 | (tabLayout?.tabSelectedIndicator as LayerDrawable).setLayerWidth(
67 | 0,
68 | tabLayout?.getTabAt(0)!!.view.width
69 | )
70 | }
71 | tabLayout?.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
72 | override fun onTabReselected(tab: TabLayout.Tab?) {
73 | }
74 |
75 | override fun onTabUnselected(tab: TabLayout.Tab?) {
76 | }
77 |
78 | override fun onTabSelected(tab: TabLayout.Tab?) {
79 | tab?.apply {
80 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
81 | (tabLayout?.tabSelectedIndicator as LayerDrawable).setLayerWidth(
82 | 0,
83 | tab.view.width
84 | )
85 | }
86 | }
87 | }
88 |
89 | })
90 | }
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/indicator/LinearIndicator.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.indicator
2 |
3 | import android.annotation.SuppressLint
4 | import android.graphics.Paint
5 | import android.graphics.drawable.LayerDrawable
6 | import android.graphics.drawable.ShapeDrawable
7 | import android.graphics.drawable.shapes.RoundRectShape
8 | import android.os.Build
9 | import android.view.Gravity
10 | import com.google.android.material.tabs.TabLayout
11 | import com.loper7.tab_expand.ext.toPx
12 |
13 | /**
14 | *
15 | * @CreateDate: 2020/8/4 17:36
16 | * @Description: LinearIndicator 线性
17 | * @Author: LOPER7
18 | * @Email: loper7@163.com
19 | */
20 | open class LinearIndicator : BaseIndicator() {
21 |
22 | protected var angle: Int = 0
23 |
24 |
25 | fun setAngle(angle: Int): LinearIndicator {
26 | this.angle = angle
27 | return this
28 | }
29 |
30 | override fun bind() {
31 | tabLayout?.post {
32 | val drawable = ShapeDrawable()
33 | if (height == MATCH)
34 | height = tabLayout?.height!!
35 | if (angle <= 0f)
36 | angle = if (height == 0) 100 else height / 2
37 | var f_angle = angle.toFloat()
38 | val outerR =
39 | floatArrayOf(f_angle, f_angle, f_angle, f_angle, f_angle, f_angle, f_angle, f_angle)
40 | val shape = RoundRectShape(outerR, null, null)
41 | drawable.shape = shape
42 | drawable.paint.style = Paint.Style.FILL
43 |
44 | val layerDrawable = LayerDrawable(arrayOf(drawable))
45 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
46 | layerDrawable.setLayerHeight(0, height)
47 | layerDrawable.setLayerWidth(0, width)
48 | layerDrawable.setLayerGravity(0, Gravity.CENTER)
49 | }
50 |
51 |
52 | if (width == 0 && height == 0)
53 | tabLayout?.setSelectedTabIndicator(drawable)
54 | else
55 | tabLayout?.setSelectedTabIndicator(layerDrawable)
56 |
57 | if (height == 0)
58 | tabLayout?.setSelectedTabIndicatorHeight(3.toPx())
59 | else
60 | tabLayout?.setSelectedTabIndicatorHeight(height)
61 |
62 | //对自适应宽度进行处理
63 | if (width <= 0 && tabLayout?.tabSelectedIndicator is LayerDrawable) {
64 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
65 | (tabLayout?.tabSelectedIndicator as LayerDrawable).setLayerWidth(
66 | 0,
67 | tabLayout?.getTabAt(0)!!.view.width
68 | )
69 | }
70 | tabLayout?.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
71 | override fun onTabReselected(tab: TabLayout.Tab?) {
72 | }
73 |
74 | override fun onTabUnselected(tab: TabLayout.Tab?) {
75 | }
76 |
77 | override fun onTabSelected(tab: TabLayout.Tab?) {
78 | tab?.apply {
79 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
80 | (tabLayout?.tabSelectedIndicator as LayerDrawable).setLayerWidth(
81 | 0,
82 | tab.view.width
83 | )
84 | }
85 | }
86 | }
87 |
88 | })
89 | }
90 | }
91 |
92 | }
93 | }
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/indicator/TriangleIndicator.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.indicator
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.graphics.Bitmap
6 | import android.graphics.drawable.*
7 | import android.os.Build
8 | import android.view.Gravity
9 | import android.view.View
10 | import androidx.annotation.RequiresApi
11 | import androidx.core.content.ContextCompat
12 | import com.loper7.tab_expand.R
13 | import com.loper7.tab_expand.ext.toDp
14 | import com.loper7.tab_expand.ext.toPx
15 |
16 |
17 | /**
18 | *
19 | * @CreateDate: 2020/8/4 17:36
20 | * @Description: TriangleIndicator 三角
21 | * @Author: LOPER7
22 | * @Email: loper7@163.com
23 | */
24 | open class TriangleIndicator : BaseIndicator() {
25 |
26 | protected var path = Path.POSITIVE
27 | private var drawable: Drawable? = null
28 |
29 | fun setPath(path: Path): TriangleIndicator {
30 | this.path = path
31 | return this
32 | }
33 |
34 |
35 | override fun bind() {
36 | tabLayout?.post {
37 | if(height==MATCH)
38 | height = tabLayout?.height!!
39 |
40 | if (drawable == null) {
41 | drawable = if (path == Path.POSITIVE) {
42 | ContextCompat.getDrawable(context!!, R.drawable.tab_indicator_triangle_z)!!
43 | } else {
44 | ContextCompat.getDrawable(context!!, R.drawable.tab_indicator_triangle_f)!!
45 | }
46 | }
47 |
48 | if (width == 0)
49 | width = 12.toPx()
50 | if (height == 0)
51 | height = 12.toPx()
52 |
53 | if (height == 0)
54 | tabLayout?.setSelectedTabIndicatorHeight(3.toPx())
55 | else
56 | tabLayout?.setSelectedTabIndicatorHeight(height)
57 |
58 | val layerDrawable = LayerDrawable(arrayOf(drawable))
59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
60 | layerDrawable.setLayerHeight(0, height)
61 | layerDrawable.setLayerWidth(0, width)
62 | layerDrawable.setLayerGravity(0, Gravity.CENTER)
63 | }
64 |
65 |
66 | tabLayout?.setSelectedTabIndicator(layerDrawable)
67 | }
68 |
69 | }
70 |
71 |
72 | enum class Path {
73 | /**
74 | * POSITIVE 正
75 | * NEGATIVE 反
76 | */
77 | POSITIVE,
78 | NEGATIVE
79 | }
80 | }
--------------------------------------------------------------------------------
/tablayout-expand/src/main/java/com/loper7/tab_expand/text/BaseText.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand.text
2 |
3 | import android.R
4 | import android.content.Context
5 | import android.view.Gravity
6 | import android.widget.LinearLayout
7 | import android.widget.TextView
8 | import androidx.annotation.ColorInt
9 | import androidx.annotation.Dimension
10 | import androidx.annotation.Px
11 | import com.google.android.material.tabs.TabLayout
12 | import com.loper7.tab_expand.ext.toPx
13 | import com.loper7.tab_expand.indicator.BaseIndicator
14 |
15 |
16 | /**
17 | *
18 | * @CreateDate: 2020/8/5 9:50
19 | * @Description: java类作用描述
20 | * @Author: LOPER7
21 | * @Email: loper7@163.com
22 | */
23 | open class BaseText {
24 |
25 | protected var context: Context? = null
26 | protected var tabLayout: TabLayout? = null
27 | protected var normalTextBold: Boolean = false
28 | protected var selectTextBold: Boolean = false
29 | protected var normalTextSize: Float = 14f
30 | protected var selectTextSize: Float = 14f
31 |
32 | fun bindTabLayout(tabLayout: TabLayout) {
33 | this.tabLayout = tabLayout
34 | this.context = tabLayout.context
35 | }
36 |
37 | fun setNormalTextBold(normalTextBold: Boolean): BaseText {
38 | this.normalTextBold = normalTextBold
39 | return this
40 | }
41 |
42 | fun setSelectTextBold(selectTextBold: Boolean): BaseText {
43 | this.selectTextBold = selectTextBold
44 | return this
45 | }
46 |
47 | fun setNormalTextSize(normalTextSize: Float): BaseText {
48 | this.normalTextSize = normalTextSize
49 | return this
50 | }
51 |
52 | fun setSelectTextSize(selectTextSize: Float): BaseText {
53 | this.selectTextSize = selectTextSize
54 | return this
55 | }
56 |
57 | fun bind() {
58 | tabLayout?.post {
59 | tabLayout?.apply {
60 | for (i in 0 until tabCount) {
61 | getTabAt(i)?.let {
62 | it.customView = TextView(context).apply {
63 | text = it.text
64 | textSize = if (selectedTabPosition==i) selectTextSize else normalTextSize
65 | if (selectedTabPosition==i)
66 | paint?.isFakeBoldText = selectTextBold
67 | else
68 | paint?.isFakeBoldText = normalTextBold
69 | gravity = Gravity.CENTER
70 | setTextColor(tabTextColors)
71 | }
72 | }
73 | }
74 |
75 | addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
76 | override fun onTabReselected(tab: TabLayout.Tab?) {
77 | (tab?.customView as? TextView)?.apply {
78 | textSize = selectTextSize
79 | paint?.isFakeBoldText = selectTextBold
80 | }
81 | }
82 |
83 | override fun onTabUnselected(tab: TabLayout.Tab?) {
84 | (tab?.customView as? TextView)?.apply {
85 | textSize = normalTextSize
86 | paint?.isFakeBoldText = normalTextBold
87 | }
88 | }
89 |
90 | override fun onTabSelected(tab: TabLayout.Tab?) {
91 | (tab?.customView as? TextView)?.apply {
92 | textSize = selectTextSize
93 | paint?.isFakeBoldText = selectTextBold
94 | }
95 | }
96 |
97 | })
98 | }
99 | }
100 |
101 | }
102 | }
--------------------------------------------------------------------------------
/tablayout-expand/src/main/res/drawable/tab_indicator_triangle_f.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/tablayout-expand/src/main/res/drawable/tab_indicator_triangle_z.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/tablayout-expand/src/test/java/com/loper7/tab_expand/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.loper7.tab_expand
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------