├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tlz │ │ └── fucktablayout │ │ └── example │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tlz │ │ │ └── fucktablayout │ │ │ └── example │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.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_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tlz │ └── fucktablayout │ └── example │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tlz │ │ └── fucktablayout │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tlz │ │ │ └── fucktablayout │ │ │ ├── Badge.kt │ │ │ ├── FuckTab.kt │ │ │ ├── FuckTabItem.kt │ │ │ ├── FuckTabLayout.kt │ │ │ ├── OnTabSelectedListener.kt │ │ │ └── RippleUtils.kt │ └── res │ │ ├── color │ │ └── mtrl_tabs_legacy_text_color_selector.xml │ │ ├── drawable │ │ └── mtrl_tabs_default_indicator.xml │ │ ├── layout │ │ ├── layout_fuck_tab_icon.xml │ │ └── layout_fuck_tab_text.xml │ │ └── values │ │ └── value.xml │ └── test │ └── java │ └── com │ └── tlz │ └── fucktablayout │ └── ExampleUnitTest.java ├── screenshot └── ezgif.com-video-to-gif.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | 44 | # Keystore files 45 | *.jks 46 | 47 | # External native build folder generated in Android Studio 2.2 and later 48 | .externalNativeBuild 49 | 50 | # Google Services (e.g. APIs or Firebase) 51 | google-services.json 52 | 53 | # Freeline 54 | freeline.py 55 | freeline/ 56 | freeline_project_description.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FuckTabLayout 2 | FuckTabLayout是直接修改的TabLayout源码,将java代码改为了kotlin代码,没有改动其原有的api,所有的自定义属性在原名上增加了`f`,如:tabMode -> fTabMode,并在基础上增加滑动文字颜色渐变以及角标设置等功能 3 | 4 | arc 5 | 6 | ## Gradle 7 | 8 | ``` 9 | implementation 'com.github.tomlezen:FuckTabLayout:1.0.9' 10 | ``` 11 | ## 使用 12 | 13 | api使用与TabLayout一致 14 | 如果需要设置指示器宽度与文字宽度一致,设置`fTabIndicatorFullWidth`属性为`false`即可 15 | 如果需要固定指示器宽度,使用`fTabIndicatorFixedWidth`属性即可 16 | 17 | 18 | ``` 19 | 添加小红点(默认color为red, radius为2dp): 20 | FuckTabLayout.addDotBadge(index, color, radius) 21 | 添加数字角标(默认color为red, textColor为white,textSize为11sp): 22 | FuckTabLayout.addNumberBadge(index, number, color, textColor, textSize) 23 | 自定义角标 24 | FuckTabLayout.addBadge(index, object: Badge(color){ 25 | override fun getMeasureWidth(): Int = 20 26 | 27 | override fun getMeasureHeight(): Int = 20 28 | 29 | override fun draw(cvs: Canvas, drawnRectF: RectF) { 30 | // 绘制 31 | } 32 | }) 33 | 移除角标 34 | FuckTabLayout.removeBadge(index) 35 | 获取角标 36 | FuckTabLayout.getBadge(index) 37 | ``` 38 | 具体细节可参考[MainActivity](https://github.com/tomlezen/FuckTabLayout/blob/master/app/src/main/java/com/tlz/fucktablayout/example/MainActivity.kt)使用 39 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "com.tlz.fucktablayout.example" 11 | minSdkVersion 14 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'androidx.appcompat:appcompat:1.1.0-alpha04' 29 | implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha03' 30 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' 31 | // implementation 'com.github.tomlezen:FuckTabLayout:1.0.0' 32 | implementation project(':lib') 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 36 | // implementation 'com.android.support:design:27.1.1' 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/tlz/fucktablayout/example/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.tlz.fucktablayout.example 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.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.getTargetContext() 22 | assertEquals("com.tlz.fucktablayout.example", 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/java/com/tlz/fucktablayout/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.tlz.fucktablayout.example 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Color 5 | import android.graphics.RectF 6 | import android.os.Bundle 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.widget.ImageView 10 | import androidx.appcompat.app.AppCompatActivity 11 | import androidx.viewpager.widget.PagerAdapter 12 | import com.tlz.fucktablayout.Badge 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | import java.util.* 15 | 16 | class MainActivity : AppCompatActivity() { 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | setContentView(R.layout.activity_main) 21 | 22 | vp_1.adapter = ViewPagerAdapter() 23 | ftl_1.setupWithViewPager(vp_1) 24 | 25 | vp_2.adapter = ViewPagerAdapter() 26 | ftl_2.setupWithViewPager(vp_2) 27 | 28 | vp_3.adapter = ViewPagerAdapter(12) 29 | ftl_3.setupWithViewPager(vp_3) 30 | 31 | // 小红点 32 | ftl_2.addDotBadge(0) 33 | // 数字角标. 34 | ftl_2.addNumberBadge(1, 1) 35 | ftl_2.addNumberBadge(2, 100) 36 | ftl_2.addNumberBadge(3, 1000) 37 | // 自定义角标 38 | ftl_2.addBadge(4, object : Badge(Color.RED) { 39 | 40 | override fun getMeasureWidth(): Int = 20 41 | 42 | override fun getMeasureHeight(): Int = 20 43 | 44 | override fun draw(cvs: Canvas, drawnRectF: RectF) { 45 | paint.color = color 46 | cvs.drawRect(drawnRectF, paint) 47 | } 48 | }) 49 | 50 | ftl_3.addDotBadge(0) 51 | // 数字角标. 52 | val numberBadge = ftl_3.addNumberBadge(1, 1) 53 | ftl_3.addNumberBadge(2, 10) 54 | 55 | btn_add_badge.setOnClickListener { 56 | ftl_3.addDotBadge(0, Color.BLUE) 57 | } 58 | 59 | btn_remove_badge.setOnClickListener { 60 | // 移除角标. 61 | ftl_3.removeBadge(0) 62 | } 63 | 64 | btn_change_number.setOnClickListener { 65 | // 修改数字. 66 | numberBadge.number = (numberBadge.number ?: 0) + 1 67 | } 68 | 69 | ftl_4.addTab(ftl_4.newTab().apply { 70 | text = "默认1" 71 | icon = getDrawable(R.mipmap.ic_launcher) 72 | }) 73 | ftl_4.addTab(ftl_4.newTab().apply { 74 | text = "默认2" 75 | icon = getDrawable(R.mipmap.ic_launcher) 76 | }, false) 77 | ftl_4.addTab(ftl_4.newTab().apply { 78 | text = "默认3" 79 | icon = getDrawable(R.mipmap.ic_launcher) 80 | }, false) 81 | ftl_4.addTab(ftl_4.newTab().apply { 82 | text = "默认4" 83 | icon = getDrawable(R.mipmap.ic_launcher) 84 | }, false) 85 | ftl_4.addTab(ftl_4.newTab().apply { 86 | text = "默认5" 87 | icon = getDrawable(R.mipmap.ic_launcher) 88 | }, false) 89 | } 90 | 91 | class ViewPagerAdapter(private val count: Int = 5) : PagerAdapter() { 92 | 93 | override fun isViewFromObject(view: View, `object`: Any): Boolean = view == `object` 94 | 95 | override fun instantiateItem(container: ViewGroup, position: Int): Any { 96 | val imageView = ImageView(container.context) 97 | imageView.setBackgroundColor(Color.rgb(Random().nextInt(255), Random().nextInt(255), Random().nextInt(255))) 98 | container.addView(imageView) 99 | return imageView 100 | } 101 | 102 | override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { 103 | container.removeView(`object` as View) 104 | } 105 | 106 | override fun getCount(): Int = count 107 | 108 | override fun getPageTitle(position: Int): CharSequence? = "Item$position" 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 23 | 24 | 28 | 29 | 38 | 39 | 43 | 44 | 53 | 54 | 58 | 59 | 64 | 65 |