├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── zhl │ │ │ └── tabindicatorviewsample │ │ │ └── MainActivity.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── zhl │ │ └── tabindicatorview │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── TabIndicatorViewLibrary ├── .gitignore ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ ├── strings.xml │ │ │ └── attrs.xml │ │ ├── java │ │ └── com │ │ │ └── zhl │ │ │ └── tabindicatorview │ │ │ ├── bean │ │ │ └── TabItem.java │ │ │ ├── util │ │ │ └── MeasureUtil.java │ │ │ └── view │ │ │ ├── TabIndicatorView.java │ │ │ └── TabItemView.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── GIF.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | TabIndicatorView -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':TabIndicatorViewLibrary' 2 | -------------------------------------------------------------------------------- /GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/GIF.gif -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TabIndicatorView 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TabIndicatorViewLibrary 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yilylong/TabIndicatorView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 24 11:16:08 CST 2017 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-3.3-all.zip 7 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/java/com/zhl/tabindicatorview/bean/TabItem.java: -------------------------------------------------------------------------------- 1 | package com.zhl.tabindicatorview.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 描述: 7 | * Created by zhaohl on 2016-9-30. 8 | */ 9 | public class TabItem implements Serializable { 10 | public int position; 11 | public String title; 12 | } 13 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zhl/tabindicatorview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.zhl.tabindicatorview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\work\AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\work\AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group='com.github.yilylong' 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.1" 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.zhl.tabindicatorviewsample" 9 | minSdkVersion 14 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile project(':TabIndicatorViewLibrary') 27 | } 28 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 25 | 26 | 27 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://www.jitpack.io/v/yilylong/TabIndicatorView.svg)](https://www.jitpack.io/#yilylong/TabIndicatorView)# TabIndicatorView 2 | 一个简单的tab导航控件 3 | 4 |
5 | 6 | useage 7 | --- 8 | step1.Add it in your root build.gradle at the end of repositories: 9 | - 10 | 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://www.jitpack.io' } 15 | } 16 | } 17 | 18 | stpe2.Add the dependency: 19 | - 20 | dependencies { 21 | compile 'com.github.yilylong:TabIndicatorView:1.0.1' 22 | } 23 | 24 | 25 | 26 | 27 | in your xml: 28 | - 29 | 30 | 42 | 43 | in code: 44 | - 45 | 46 | TabIndicatorView indicatorView = (TabIndicatorView) findViewById(R.id.tab_indicator_view); 47 | 48 | indicatorView.initTabs(items, new TabIndicatorView.OnTabItemCheckListener() { 49 | @Override 50 | public void onTabItemCheck(TabItemView itemTabView, int position) { 51 | Toast.makeText(MainActivity.this,"当前选中=="+position,Toast.LENGTH_SHORT).show(); 52 | } 53 | }); 54 | 具体属性见源码 55 | --- 56 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/res/values/attrs.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 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhl/tabindicatorviewsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhl.tabindicatorviewsample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.Toast; 8 | 9 | import com.zhl.tabindicatorview.bean.TabItem; 10 | import com.zhl.tabindicatorview.view.TabIndicatorView; 11 | import com.zhl.tabindicatorview.view.TabItemView; 12 | 13 | import java.util.ArrayList; 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | private int position; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_main); 22 | TabIndicatorView indicatorView = (TabIndicatorView) findViewById(R.id.tab_indicator_view); 23 | TabIndicatorView indicatorView2 = (TabIndicatorView) findViewById(R.id.tab_indicator_view2); 24 | final PswdInputView inputView = (PswdInputView) findViewById(R.id.tab_indicator_view3); 25 | Button remove = (Button) findViewById(R.id.removebtn); 26 | Button addbtn = (Button) findViewById(R.id.addBtn); 27 | ArrayList items = new ArrayList(); 28 | for (int i = 0; i < 4; i++) { 29 | TabItem item = new TabItem(); 30 | item.title = "近" + (i + 1) + "月"; 31 | item.position = i; 32 | items.add(item); 33 | } 34 | indicatorView.initTabs(items, new TabIndicatorView.OnTabItemCheckListener() { 35 | @Override 36 | public void onTabItemCheck(TabItemView itemTabView, int position) { 37 | Toast.makeText(MainActivity.this, "当前选中==" + position, Toast.LENGTH_SHORT).show(); 38 | } 39 | }); 40 | indicatorView.setDefaultCheckedPos(1); 41 | 42 | ArrayList items2 = new ArrayList(); 43 | for (int i = 0; i < 4; i++) { 44 | TabItem item = new TabItem(); 45 | item.title = "第" + (i + 1) + "季度"; 46 | item.position = i; 47 | items2.add(item); 48 | } 49 | indicatorView2.initTabs(items2, new TabIndicatorView.OnTabItemCheckListener() { 50 | @Override 51 | public void onTabItemCheck(TabItemView itemTabView, int position) { 52 | Toast.makeText(MainActivity.this, "当前选中==" + position, Toast.LENGTH_SHORT).show(); 53 | } 54 | }); 55 | indicatorView2.setDefaultCheckedPos(0); 56 | inputView.initTabs(6); 57 | remove.setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | if(position>0){ 61 | --position; 62 | } 63 | inputView.removePsw(position); 64 | } 65 | }); 66 | addbtn.setOnClickListener(new View.OnClickListener() { 67 | @Override 68 | public void onClick(View v) { 69 | inputView.insertPsw(position); 70 | if(position<6){ 71 | ++position; 72 | } 73 | } 74 | }); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/java/com/zhl/tabindicatorview/util/MeasureUtil.java: -------------------------------------------------------------------------------- 1 | package com.zhl.tabindicatorview.util; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.graphics.Bitmap; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.util.DisplayMetrics; 10 | import android.util.TypedValue; 11 | import android.view.View.MeasureSpec; 12 | 13 | /** 14 | * 测绘工具类 15 | * @since 2014/11/19 16 | */ 17 | public final class MeasureUtil { 18 | public static final int RATION_WIDTH = 0; 19 | public static final int RATION_HEIGHT = 1; 20 | 21 | /** 22 | * 获取屏幕尺寸 23 | * 24 | * @param activity 25 | * Activity 26 | * @return 屏幕尺寸像素值,下标为0的值为宽,下标为1的值为高 27 | */ 28 | public static int[] getScreenSize(Activity activity) { 29 | DisplayMetrics metrics = new DisplayMetrics(); 30 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 31 | return new int[] { metrics.widthPixels, metrics.heightPixels }; 32 | } 33 | 34 | /** 35 | * 自定义控件获取测量后的尺寸方法 36 | * 37 | * @param measureSpec 38 | * 测量规格 39 | * @param ratio 40 | * 宽高标识 41 | * @param resSize 42 | * 资源(图片bitmap)的宽或高 43 | * @param paddings 44 | * 自定义控件的padding值int[]{left,top,right,bottom} 45 | * 46 | * @return 宽或高的测量值 47 | */ 48 | public static int getMeasureSize(int measureSpec, int ratio,int resSize,int[] paddings) { 49 | // 声明临时变量保存测量值 50 | int result = 0; 51 | /* 52 | * 获取测量mode和size 53 | */ 54 | int mode = MeasureSpec.getMode(measureSpec); 55 | int size = MeasureSpec.getSize(measureSpec); 56 | /* 57 | * 判断mode的具体值 58 | */ 59 | switch (mode) { 60 | case MeasureSpec.EXACTLY:// EXACTLY时直接赋值 61 | result = size; 62 | break; 63 | default:// 默认情况下将UNSPECIFIED和AT_MOST一并处理 64 | result+=resSize; 65 | if (ratio == RATION_WIDTH) { 66 | if(paddings!=null){ 67 | result+=( paddings[0] + paddings[2]); 68 | } 69 | } else if (ratio == RATION_HEIGHT) { 70 | if(paddings!=null){ 71 | result+=( paddings[1] + paddings[3]); 72 | } 73 | } 74 | /* 75 | * AT_MOST时判断size和result的大小取小值 76 | */ 77 | if (mode == MeasureSpec.AT_MOST) { 78 | result = Math.min(result, size); 79 | } 80 | break; 81 | } 82 | return result; 83 | } 84 | public static Bitmap changeColor(Bitmap src, int keyColor, int replColor, int tolerance) { 85 | Bitmap copy = src.copy(Bitmap.Config.ARGB_8888, true); 86 | int width = copy.getWidth(); 87 | int height = copy.getHeight(); 88 | int[] pixels = new int[width * height]; 89 | src.getPixels(pixels, 0, width, 0, 0, width, height); 90 | int sR = Color.red(keyColor); 91 | int sG = Color.green(keyColor); 92 | int sB = Color.blue(keyColor); 93 | int tR = Color.red(replColor); 94 | int tG = Color.green(replColor); 95 | int tB = Color.blue(replColor); 96 | float[] hsv = new float[3]; 97 | Color.RGBToHSV(tR, tG, tB, hsv); 98 | float targetHue = hsv[0]; 99 | float targetSat = hsv[1]; 100 | float targetVal = hsv[2]; 101 | 102 | for (int i = 0; i < pixels.length; ++i) { 103 | int pixel = pixels[i]; 104 | 105 | if (pixel == keyColor) { 106 | pixels[i] = replColor; 107 | } else { 108 | int pR = Color.red(pixel); 109 | int pG = Color.green(pixel); 110 | int pB = Color.blue(pixel); 111 | 112 | int deltaR = Math.abs(pR - sR); 113 | int deltaG = Math.abs(pG - sG); 114 | int deltaB = Math.abs(pB - sB); 115 | 116 | if (deltaR <= tolerance && deltaG <= tolerance && deltaB <= tolerance) { 117 | Color.RGBToHSV(pR, pG, pB, hsv); 118 | hsv[0] = targetHue; 119 | hsv[1] = targetSat; 120 | hsv[2] *= targetVal; 121 | 122 | int mixTrgColor = Color.HSVToColor(Color.alpha(pixel), hsv); 123 | pixels[i] = mixTrgColor; 124 | } 125 | } 126 | } 127 | 128 | copy.setPixels(pixels, 0, width, 0, 0, width, height); 129 | 130 | return copy; 131 | } 132 | 133 | public static int dp2px(Context context,int dp) { 134 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); 135 | } 136 | public static int sp2px(Context context,int dp) { 137 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, context.getResources().getDisplayMetrics()); 138 | } 139 | 140 | /** 141 | * 测量文字的高度 142 | * @param textsize px 143 | * @return 144 | */ 145 | public static int measureTextHeight(int textsize){ 146 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 147 | paint.setTextSize(textsize); 148 | Paint.FontMetrics metrics = paint.getFontMetrics(); 149 | return (int) Math.ceil(metrics.descent-metrics.ascent); 150 | } 151 | 152 | /** 153 | * 测量文字的宽度 154 | * @param text 155 | * @param textsize px 156 | * @return 157 | */ 158 | public static int measureTextWidth(String text,int textsize){ 159 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 160 | paint.setTextSize(textsize); 161 | return (int) paint.measureText(text); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/java/com/zhl/tabindicatorview/view/TabIndicatorView.java: -------------------------------------------------------------------------------- 1 | package com.zhl.tabindicatorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.view.ViewGroup; 7 | import android.widget.LinearLayout; 8 | 9 | import com.zhl.tabindicatorview.R; 10 | import com.zhl.tabindicatorview.bean.TabItem; 11 | 12 | import java.util.ArrayList; 13 | 14 | /** 15 | * 描述: 16 | * Created by zhaohl on 2016-9-30. 17 | */ 18 | public class TabIndicatorView extends LinearLayout { 19 | private ArrayList tabItemViews = new ArrayList(); 20 | private ArrayList tabItems = new ArrayList(); 21 | private OnTabItemCheckListener onTabItemCheckListener; 22 | private int tabTextSize = -1; 23 | private int cornerRadiu = -1; 24 | private int borderWidth = -1; 25 | private int tabCheckedTextColor = -1; 26 | private int tabUnCheckedTextColor = -1; 27 | private int tabCheckBGcolor = -1; 28 | private int tabUnCheckBGcolor = -1; 29 | private int defaultCheckedPos = -1; 30 | 31 | public TabIndicatorView(Context context) { 32 | this(context, null); 33 | } 34 | 35 | public TabIndicatorView(Context context, AttributeSet attrs) { 36 | this(context, attrs, -1); 37 | } 38 | 39 | public TabIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) { 40 | super(context, attrs, defStyleAttr); 41 | setOrientation(LinearLayout.HORIZONTAL); 42 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TabIndicatorView); 43 | tabCheckedTextColor = array.getColor(R.styleable.TabIndicatorView_tabCheckedTextColor,-1); 44 | tabUnCheckedTextColor = array.getColor(R.styleable.TabIndicatorView_tabUnCheckedTextColor,-1); 45 | tabCheckBGcolor = array.getColor(R.styleable.TabIndicatorView_tabCheckBGcolor,-1); 46 | tabUnCheckBGcolor = array.getColor(R.styleable.TabIndicatorView_tabUnCheckBGcolor,-1); 47 | tabTextSize = array.getInteger(R.styleable.TabIndicatorView_tabTextSize,-1); 48 | cornerRadiu = array.getInteger(R.styleable.TabIndicatorView_tabCornerRadiu,-1); 49 | borderWidth = array.getInteger(R.styleable.TabIndicatorView_tabBorderWidth,-1); 50 | array.recycle(); 51 | } 52 | 53 | public void initTabs(ArrayList tabItems,OnTabItemCheckListener onTabCheckListener) { 54 | this.tabItems = tabItems; 55 | this.onTabItemCheckListener = onTabCheckListener; 56 | if(null!=tabItems){ 57 | for(TabItem item:tabItems){ 58 | TabItemView itemView = new TabItemView(getContext(),item.title,item.position,tabItems.size()); 59 | if(tabCheckedTextColor!=-1){ 60 | itemView.setTitleSelectedColor(tabCheckedTextColor); 61 | } 62 | if(tabUnCheckedTextColor!=-1){ 63 | itemView.setTitleUnselectedColor(tabUnCheckedTextColor); 64 | } 65 | if(tabCheckBGcolor!=-1){ 66 | itemView.setTabStrokeCheckedColor(tabCheckBGcolor); 67 | } 68 | if(tabUnCheckBGcolor!=-1){ 69 | itemView.setTabStrokeUncheckColor(tabUnCheckBGcolor); 70 | } 71 | if(tabTextSize!=-1){ 72 | itemView.setTextSize(tabTextSize); 73 | } 74 | if(cornerRadiu!=-1){ 75 | itemView.setRoundRadiu(cornerRadiu); 76 | } 77 | if(borderWidth!=-1){ 78 | itemView.setTabStrokeWidth(borderWidth); 79 | } 80 | LayoutParams params = new LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT); 81 | params.weight = 1; 82 | if(item.position==0){ 83 | params.rightMargin = -itemView.getTabStrokeWidth(); 84 | }else if(item.position==tabItems.size()-1){ 85 | params.leftMargin = -itemView.getTabStrokeWidth(); 86 | }else{ 87 | params.leftMargin = -itemView.getTabStrokeWidth(); 88 | params.rightMargin = -itemView.getTabStrokeWidth(); 89 | } 90 | addView(itemView,params); 91 | itemView.setOnTapListener(new TabItemView.OnTapListener() { 92 | @Override 93 | public void onTaped(TabItemView seatView, int position) { 94 | if(onTabItemCheckListener!=null){ 95 | onTabItemCheckListener.onTabItemCheck(seatView,position); 96 | } 97 | for(int i=0;i getTabItems() { 179 | return tabItems; 180 | } 181 | 182 | public int getDefaultCheckedPos() { 183 | return defaultCheckedPos; 184 | } 185 | 186 | public void setDefaultCheckedPos(int defaultCheckedPos) { 187 | if(defaultCheckedPos<0){ 188 | return; 189 | } 190 | this.defaultCheckedPos = defaultCheckedPos; 191 | if(tabItemViews!=null&&tabItemViews.size()>0){ 192 | tabItemViews.get(defaultCheckedPos).setState(TabItemView.STATE_SELECTED); 193 | } 194 | } 195 | 196 | public void invidateData(){ 197 | if(tabItemViews!=null&&tabItemViews.size()>0){ 198 | removeAllViews(); 199 | tabItemViews.clear(); 200 | initTabs(tabItems,onTabItemCheckListener); 201 | requestLayout(); 202 | } 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /TabIndicatorViewLibrary/src/main/java/com/zhl/tabindicatorview/view/TabItemView.java: -------------------------------------------------------------------------------- 1 | package com.zhl.tabindicatorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Path; 8 | import android.graphics.PointF; 9 | import android.graphics.Rect; 10 | import android.graphics.RectF; 11 | import android.util.AttributeSet; 12 | import android.view.MotionEvent; 13 | import android.view.View; 14 | 15 | import com.zhl.tabindicatorview.R; 16 | import com.zhl.tabindicatorview.util.MeasureUtil; 17 | 18 | /** 19 | * 描述:一个导航tab的item 20 | * Created by zhaohl on 2016-7-25. 21 | */ 22 | public class TabItemView extends View { 23 | public static final int STATE_UNSELECTED = 0; 24 | public static final int STATE_SELECTED = 1; 25 | private int tabStrokeUncheckColor = 0xFFB5B5B5; 26 | private int tabStrokeCheckedColor = 0xFFB5B5B5; 27 | private int titleUnselectedColor = 0xFFB5B5B5; 28 | private int titleSelectedColor = 0xFF000000; 29 | private int tabStrokeWidth = 3; 30 | private int position; 31 | private String title; 32 | private int state = STATE_UNSELECTED; 33 | private OnTapListener onTapListener; 34 | private Paint paint; 35 | private int tabsCount = 4; 36 | private int textSize = 30; 37 | private int roundRadiu = 5; 38 | 39 | public TabItemView(Context context, String title, int position, int tabsCount) { 40 | this(context); 41 | this.title = title; 42 | this.position = position; 43 | this.tabsCount = tabsCount; 44 | } 45 | 46 | public TabItemView(Context context) { 47 | this(context, null); 48 | } 49 | 50 | public TabItemView(Context context, AttributeSet attrs) { 51 | this(context, attrs, -1); 52 | } 53 | 54 | public TabItemView(Context context, AttributeSet attrs, int defStyleAttr) { 55 | super(context, attrs, defStyleAttr); 56 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TabItemView); 57 | tabStrokeUncheckColor = array.getColor(R.styleable.TabItemView_tab_strokeuncheck_color, tabStrokeUncheckColor); 58 | tabStrokeCheckedColor = array.getColor(R.styleable.TabItemView_tab_strokecheck_color, tabStrokeCheckedColor); 59 | tabStrokeWidth = MeasureUtil.dp2px(context, array.getInteger(R.styleable.TabItemView_tab_stroke_width, 0)); 60 | if (tabStrokeWidth == 0) { 61 | tabStrokeWidth = 3; 62 | } 63 | titleUnselectedColor = array.getColor(R.styleable.TabItemView_title_unselected_color, titleUnselectedColor); 64 | titleSelectedColor = array.getColor(R.styleable.TabItemView_title_selected_color, titleSelectedColor); 65 | state = array.getInteger(R.styleable.TabItemView_tab_state, 0); 66 | textSize = MeasureUtil.dp2px(context, array.getInteger(R.styleable.TabItemView_tab_textsize, 0)); 67 | if (textSize == 0) { 68 | textSize = 50; 69 | } 70 | roundRadiu = MeasureUtil.dp2px(context, array.getInteger(R.styleable.TabItemView_tab_roundradiu, 10)); 71 | title = array.getString(R.styleable.TabItemView_tab_title); 72 | position = array.getInteger(R.styleable.TabItemView_tab_position, 1); 73 | array.recycle(); 74 | paint = new Paint(Paint.ANTI_ALIAS_FLAG); 75 | } 76 | 77 | 78 | public void setRoundRadiu(int roundRadiu) { 79 | this.roundRadiu = roundRadiu; 80 | invalidate(); 81 | } 82 | 83 | public int getTitleSelectedColor() { 84 | return titleSelectedColor; 85 | } 86 | 87 | public void setTitleSelectedColor(int titleSelectedColor) { 88 | this.titleSelectedColor = titleSelectedColor; 89 | invalidate(); 90 | } 91 | 92 | public int getTitleUnselectedColor() { 93 | return titleUnselectedColor; 94 | } 95 | 96 | public void setTitleUnselectedColor(int titleUnselectedColor) { 97 | this.titleUnselectedColor = titleUnselectedColor; 98 | invalidate(); 99 | } 100 | 101 | public int getTabStrokeWidth() { 102 | return tabStrokeWidth; 103 | } 104 | 105 | @Override 106 | public boolean onTouchEvent(MotionEvent event) { 107 | switch (event.getAction()) { 108 | case MotionEvent.ACTION_DOWN: 109 | return true; 110 | case MotionEvent.ACTION_MOVE: 111 | break; 112 | case MotionEvent.ACTION_UP: 113 | setState(STATE_SELECTED); 114 | break; 115 | } 116 | return super.onTouchEvent(event); 117 | } 118 | 119 | public int getPosition() { 120 | return position; 121 | } 122 | 123 | public void setPosition(int position) { 124 | this.position = position; 125 | } 126 | 127 | public String getTitle() { 128 | return title; 129 | } 130 | 131 | public void setTitle(String title) { 132 | this.title = title; 133 | } 134 | 135 | @Override 136 | protected void onDraw(Canvas canvas) { 137 | switch (state) { 138 | case STATE_UNSELECTED: 139 | drawUnchecked(canvas); 140 | break; 141 | case STATE_SELECTED: 142 | drawChecked(canvas); 143 | break; 144 | } 145 | } 146 | 147 | private void drawChecked(Canvas canvas) { 148 | paint.setColor(tabStrokeCheckedColor); 149 | paint.setStyle(Paint.Style.FILL); 150 | float border = tabStrokeWidth/2; 151 | if (position == 0) { 152 | // Path path = new Path(); 153 | // path.moveTo(roundRadiu, 0); 154 | // path.lineTo(getMeasuredWidth(), 0); 155 | // path.lineTo(getMeasuredWidth(), getMeasuredHeight()); 156 | // path.lineTo(roundRadiu, getMeasuredHeight()); 157 | // RectF arcLeftBottom = new RectF(0, getMeasuredHeight() - 2 * roundRadiu, 2 * roundRadiu, getMeasuredHeight()); 158 | // path.arcTo(arcLeftBottom, 90, 90); 159 | // path.lineTo(0, roundRadiu); 160 | // RectF arcLeftTop = new RectF(0, 0, 2 * roundRadiu, 2 * roundRadiu); 161 | // path.arcTo(arcLeftTop, 180, 90); 162 | // canvas.drawPath(path, paint); 163 | Path path = new Path(); 164 | PointF pointTopLeft = new PointF(border+roundRadiu, border); 165 | PointF pointTopRight = new PointF(getMeasuredWidth()-border, border); 166 | PointF pointBottomRight = new PointF(getMeasuredWidth()-border, getMeasuredHeight()-border); 167 | PointF pointBottomLeft = new PointF(border+roundRadiu, getMeasuredHeight()-border); 168 | RectF arcLeftBottom = new RectF(border, getMeasuredHeight()-border - 2 * roundRadiu, 2 * roundRadiu+border, getMeasuredHeight()-border); 169 | RectF arcLeftTop = new RectF(border, border, 2 * roundRadiu+border, 2 * roundRadiu+border); 170 | path.moveTo(pointTopLeft.x,pointTopLeft.y); 171 | path.lineTo(pointTopRight.x,pointTopRight.y); 172 | path.lineTo(pointBottomRight.x,pointBottomRight.y); 173 | path.lineTo(pointBottomLeft.x,pointBottomLeft.y); 174 | path.arcTo(arcLeftBottom, 90, 90); 175 | path.lineTo(border, roundRadiu+border); 176 | path.arcTo(arcLeftTop, 180, 90); 177 | canvas.drawPath(path, paint); 178 | 179 | } else if (position == tabsCount - 1) { 180 | // Path path = new Path(); 181 | // path.moveTo(0, 0); 182 | // path.lineTo(getMeasuredWidth() - roundRadiu, 0); 183 | // RectF arcRightTop = new RectF(getMeasuredWidth() - 2 * roundRadiu, 0, getMeasuredWidth(), 2 * roundRadiu); 184 | // path.arcTo(arcRightTop, 270, 90); 185 | // path.lineTo(getMeasuredWidth(), getMeasuredHeight() - roundRadiu); 186 | // RectF arcRightBottom = new RectF(getMeasuredWidth() - 2 * roundRadiu, getMeasuredHeight() - 2 * roundRadiu, getMeasuredWidth(), getMeasuredHeight()); 187 | // path.arcTo(arcRightBottom, 0, 90); 188 | // path.lineTo(0, getMeasuredHeight()); 189 | // path.close(); 190 | // canvas.drawPath(path, paint); 191 | 192 | Path path = new Path(); 193 | // 左上 194 | path.moveTo(border, border); 195 | // 右上 196 | path.lineTo(getMeasuredWidth()-border - roundRadiu, border); 197 | // 右上圆弧 198 | RectF arcRightTop = new RectF(getMeasuredWidth()-border - 2 * roundRadiu, border, getMeasuredWidth()-border, 2 * roundRadiu+border); 199 | path.arcTo(arcRightTop, 270, 90); 200 | // 右下 201 | path.lineTo(getMeasuredWidth()-border, getMeasuredHeight()-border - roundRadiu); 202 | // 右下圆弧 203 | RectF arcRightBottom = new RectF(getMeasuredWidth() -border- 2 * roundRadiu, getMeasuredHeight() -border- 2 * roundRadiu, getMeasuredWidth()-border, getMeasuredHeight()-border); 204 | path.arcTo(arcRightBottom, 0, 90); 205 | // 左下 206 | path.lineTo(border, getMeasuredHeight()-border); 207 | path.close(); 208 | canvas.drawPath(path, paint); 209 | 210 | } else { 211 | canvas.drawRect(new RectF(border, border, getMeasuredWidth()-border, getMeasuredHeight()-border), paint); 212 | } 213 | paint.setTextSize(textSize); 214 | paint.setStyle(Paint.Style.FILL); 215 | paint.setColor(titleSelectedColor); 216 | Rect rect = new Rect(); 217 | paint.getTextBounds(title, 0, title.length(), rect); 218 | float textWidth = rect.width(); 219 | Paint.FontMetrics metrics = paint.getFontMetrics(); 220 | float baseline = (getMeasuredHeight() - metrics.bottom + metrics.top) / 2 - metrics.top; 221 | canvas.drawText(title, getWidth() / 2 - textWidth / 2, baseline, paint); 222 | if (onTapListener != null) { 223 | onTapListener.onTaped(this, position); 224 | } 225 | } 226 | 227 | private void drawUnchecked(Canvas canvas) { 228 | paint.setColor(tabStrokeUncheckColor); 229 | paint.setStyle(Paint.Style.STROKE); 230 | paint.setStrokeWidth(tabStrokeWidth); 231 | if (position == 0) { 232 | Path path = new Path(); 233 | PointF pointTopLeft = new PointF(tabStrokeWidth+roundRadiu, tabStrokeWidth); 234 | PointF pointTopRight = new PointF(getMeasuredWidth()-tabStrokeWidth, tabStrokeWidth); 235 | PointF pointBottomRight = new PointF(getMeasuredWidth()-tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth); 236 | PointF pointBottomLeft = new PointF(tabStrokeWidth+roundRadiu, getMeasuredHeight()-tabStrokeWidth); 237 | RectF arcLeftBottom = new RectF(tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth - 2 * roundRadiu, 2 * roundRadiu+tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth); 238 | RectF arcLeftTop = new RectF(tabStrokeWidth, tabStrokeWidth, 2 * roundRadiu+tabStrokeWidth, 2 * roundRadiu+tabStrokeWidth); 239 | path.moveTo(pointTopLeft.x,pointTopLeft.y); 240 | path.lineTo(pointTopRight.x,pointTopRight.y); 241 | path.lineTo(pointBottomRight.x,pointBottomRight.y); 242 | path.lineTo(pointBottomLeft.x,pointBottomLeft.y); 243 | path.arcTo(arcLeftBottom, 90, 90); 244 | path.lineTo(tabStrokeWidth, roundRadiu+tabStrokeWidth); 245 | path.arcTo(arcLeftTop, 180, 90); 246 | canvas.drawPath(path, paint); 247 | } else if (position == tabsCount - 1) { 248 | Path path = new Path(); 249 | // 左上 250 | path.moveTo(tabStrokeWidth, tabStrokeWidth); 251 | // 右上 252 | path.lineTo(getMeasuredWidth()-tabStrokeWidth - roundRadiu, tabStrokeWidth); 253 | // 右上圆弧 254 | RectF arcRightTop = new RectF(getMeasuredWidth()-tabStrokeWidth - 2 * roundRadiu, tabStrokeWidth, getMeasuredWidth()-tabStrokeWidth, 2 * roundRadiu+tabStrokeWidth); 255 | path.arcTo(arcRightTop, 270, 90); 256 | // 右下 257 | path.lineTo(getMeasuredWidth()-tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth - roundRadiu); 258 | // 右下圆弧 259 | RectF arcRightBottom = new RectF(getMeasuredWidth() -tabStrokeWidth- 2 * roundRadiu, getMeasuredHeight() -tabStrokeWidth- 2 * roundRadiu, getMeasuredWidth()-tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth); 260 | path.arcTo(arcRightBottom, 0, 90); 261 | // 左下 262 | path.lineTo(tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth); 263 | path.close(); 264 | canvas.drawPath(path, paint); 265 | } else { 266 | canvas.drawRect(new RectF(tabStrokeWidth, tabStrokeWidth, getMeasuredWidth()-tabStrokeWidth, getMeasuredHeight()-tabStrokeWidth),paint); 267 | } 268 | paint.setTextSize(textSize); 269 | paint.setStyle(Paint.Style.FILL); 270 | paint.setColor(titleUnselectedColor); 271 | // float textHeight = getTextHeight(paint); 272 | Rect rect = new Rect(); 273 | paint.getTextBounds(title, 0, title.length(), rect); 274 | float textWidth = rect.width(); 275 | Paint.FontMetrics metrics = paint.getFontMetrics(); 276 | float baseline = (getMeasuredHeight() - metrics.bottom + metrics.top) / 2 - metrics.top; 277 | canvas.drawText(title, getWidth() / 2 - textWidth / 2, baseline, paint); 278 | } 279 | 280 | public int getTabStrokeCheckedColor() { 281 | return tabStrokeCheckedColor; 282 | } 283 | 284 | public void setTabStrokeCheckedColor(int tabStrokeCheckedColor) { 285 | this.tabStrokeCheckedColor = tabStrokeCheckedColor; 286 | } 287 | 288 | public int getTabStrokeUncheckColor() { 289 | return tabStrokeUncheckColor; 290 | } 291 | 292 | public void setTabStrokeUncheckColor(int tabStrokeUncheckColor) { 293 | this.tabStrokeUncheckColor = tabStrokeUncheckColor; 294 | } 295 | 296 | public void setTabStrokeWidth(int tabStrokeWidth) { 297 | this.tabStrokeWidth = tabStrokeWidth; 298 | postInvalidate(); 299 | } 300 | 301 | public void setTabsCount(int tabsCount) { 302 | this.tabsCount = tabsCount; 303 | postInvalidate(); 304 | } 305 | 306 | public void setTextSize(int textSize) { 307 | this.textSize = textSize; 308 | postInvalidate(); 309 | } 310 | 311 | public void setState(int state) { 312 | this.state = state; 313 | postInvalidate(); 314 | } 315 | 316 | public int getState() { 317 | return this.state; 318 | } 319 | 320 | public boolean isSelected() { 321 | return this.state == STATE_SELECTED; 322 | } 323 | 324 | 325 | public void setOnTapListener(OnTapListener tapListener) { 326 | this.onTapListener = tapListener; 327 | } 328 | 329 | private float getTextHeight(Paint p) { 330 | Paint.FontMetrics fontMetrics = p.getFontMetrics(); 331 | return fontMetrics.descent - fontMetrics.ascent; 332 | } 333 | 334 | public interface OnTapListener { 335 | public void onTaped(TabItemView seatView, int position); 336 | } 337 | } 338 | --------------------------------------------------------------------------------