├── .gitignore ├── ColorViewDemo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wei │ │ └── android │ │ └── lib │ │ └── colorview │ │ └── demo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── wei │ │ │ └── android │ │ │ └── lib │ │ │ └── colorview │ │ │ └── demo │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ ├── p1.png │ │ ├── p2.png │ │ ├── p3.png │ │ └── p4.png │ │ ├── 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 │ └── wei │ └── android │ └── lib │ └── colorview │ └── demo │ └── ExampleUnitTest.java ├── ColorViewLib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wei │ │ └── android │ │ └── lib │ │ └── colorview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── wei │ │ │ └── android │ │ │ └── lib │ │ │ └── colorview │ │ │ ├── drawable │ │ │ └── CompoundDrawables.java │ │ │ ├── helper │ │ │ ├── ColorImageViewHelper.java │ │ │ ├── ColorTextViewHelper.java │ │ │ └── ColorViewHelper.java │ │ │ ├── utils │ │ │ └── Constant.java │ │ │ └── view │ │ │ ├── ColorButton.java │ │ │ ├── ColorEditText.java │ │ │ ├── ColorFrameLayout.java │ │ │ ├── ColorImageView.java │ │ │ ├── ColorLinearLayout.java │ │ │ ├── ColorRelativeLayout.java │ │ │ ├── ColorTextView.java │ │ │ └── ColorView.java │ └── res │ │ └── values │ │ └── attrs.xml │ └── test │ └── java │ └── com │ └── wei │ └── android │ └── lib │ └── colorview │ └── ExampleUnitTest.java ├── LICENSE ├── README.md ├── build.gradle ├── demo.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /ColorViewDemo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ColorViewDemo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | applicationId "com.wei.android.lib.colorview.demo" 8 | minSdkVersion 16 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | android { 23 | lintOptions { 24 | abortOnError false 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(include: ['*.jar'], dir: 'libs') 31 | implementation 'androidx.appcompat:appcompat:1.2.0' 32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 33 | testImplementation 'junit:junit:4.13.1' 34 | androidTestImplementation 'androidx.test:runner:1.3.0' 35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 36 | implementation project(':ColorViewLib') 37 | } 38 | -------------------------------------------------------------------------------- /ColorViewDemo/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 | -------------------------------------------------------------------------------- /ColorViewDemo/src/androidTest/java/com/wei/android/lib/colorview/demo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.demo; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.wei.android.lib.colorview.demo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/java/com/wei/android/lib/colorview/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.demo; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/drawable-xxhdpi/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/drawable-xxhdpi/p1.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/drawable-xxhdpi/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/drawable-xxhdpi/p2.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/drawable-xxhdpi/p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/drawable-xxhdpi/p3.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/drawable-xxhdpi/p4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/drawable-xxhdpi/p4.png -------------------------------------------------------------------------------- /ColorViewDemo/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 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 24 | 25 | 44 | 45 | 54 | 55 | 66 | 67 | 72 | 73 | 74 | 75 | 90 | 91 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/ColorViewDemo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ColorViewDemo 3 | 4 | -------------------------------------------------------------------------------- /ColorViewDemo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ColorViewDemo/src/test/java/com/wei/android/lib/colorview/demo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.demo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /ColorViewLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ColorViewLib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'com.github.panpf.bintray-publish' 4 | } 5 | 6 | android { 7 | compileSdkVersion 28 8 | 9 | defaultConfig { 10 | minSdkVersion 16 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | android { 26 | lintOptions { 27 | abortOnError false 28 | } 29 | } 30 | } 31 | 32 | publish { 33 | userOrg = 'uccmawei' 34 | groupId = 'com.wei.android.lib' 35 | artifactId = 'colorview' 36 | publishVersion = '1.3.5' 37 | desc = 'Encoder your colorful selector with XML.' 38 | website = 'https://github.com/uccmawei/ColorView' 39 | } 40 | 41 | dependencies { 42 | implementation fileTree(dir: 'libs', include: ['*.jar']) 43 | implementation 'androidx.appcompat:appcompat:1.2.0' 44 | testImplementation 'junit:junit:4.13.1' 45 | androidTestImplementation 'androidx.test:runner:1.3.0' 46 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 47 | } -------------------------------------------------------------------------------- /ColorViewLib/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 | -------------------------------------------------------------------------------- /ColorViewLib/src/androidTest/java/com/wei/android/lib/colorview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.wei.android.lib.colorview.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/drawable/CompoundDrawables.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.drawable; 2 | 3 | import android.content.res.TypedArray; 4 | import android.graphics.drawable.Drawable; 5 | import android.graphics.drawable.StateListDrawable; 6 | import android.widget.TextView; 7 | 8 | import com.wei.android.lib.colorview.utils.Constant; 9 | 10 | /** 11 | * Created by UCCMAWEI on 2018/12/27. 12 | */ 13 | 14 | public class CompoundDrawables { 15 | 16 | private final TextView mTextView; 17 | 18 | // 边缘图标 19 | private StateListDrawable mCompoundDrawablesLeft; 20 | private StateListDrawable mCompoundDrawablesTop; 21 | private StateListDrawable mCompoundDrawablesRight; 22 | private StateListDrawable mCompoundDrawablesBottom; 23 | 24 | // 边缘图标 25 | public Drawable mDrawableLeftNormal; 26 | public Drawable mDrawableLeftPressed; 27 | public Drawable mDrawableLeftSelected; 28 | public Drawable mDrawableLeftChecked; 29 | public Drawable mDrawableLeftUnable; 30 | 31 | // 边缘图标 32 | public Drawable mDrawableTopNormal; 33 | public Drawable mDrawableTopPressed; 34 | public Drawable mDrawableTopSelected; 35 | public Drawable mDrawableTopChecked; 36 | public Drawable mDrawableTopUnable; 37 | 38 | // 边缘图标 39 | public Drawable mDrawableRightNormal; 40 | public Drawable mDrawableRightPressed; 41 | public Drawable mDrawableRightSelected; 42 | public Drawable mDrawableRightChecked; 43 | public Drawable mDrawableRightUnable; 44 | 45 | // 边缘图标 46 | public Drawable mDrawableBottomNormal; 47 | public Drawable mDrawableBottomPressed; 48 | public Drawable mDrawableBottomSelected; 49 | public Drawable mDrawableBottomChecked; 50 | public Drawable mDrawableBottomUnable; 51 | 52 | // 图标大小 53 | public int mDrawableLeftWidth; 54 | public int mDrawableLeftHeight; 55 | public int mDrawableTopWidth; 56 | public int mDrawableTopHeight; 57 | public int mDrawableRightWidth; 58 | public int mDrawableRightHeight; 59 | public int mDrawableBottomWidth; 60 | public int mDrawableBottomHeight; 61 | 62 | public CompoundDrawables(TextView textView, 63 | TypedArray typedArray, 64 | 65 | int drawableLeftNormal, 66 | int drawableLeftPressed, 67 | int drawableLeftSelected, 68 | int drawableLeftChecked, 69 | int drawableLeftUnable, 70 | 71 | int drawableTopNormal, 72 | int drawableTopPressed, 73 | int drawableTopSelected, 74 | int drawableTopChecked, 75 | int drawableTopUnable, 76 | 77 | int drawableRightNormal, 78 | int drawableRightPressed, 79 | int drawableRightSelected, 80 | int drawableRightChecked, 81 | int drawableRightUnable, 82 | 83 | int drawableBottomNormal, 84 | int drawableBottomPressed, 85 | int drawableBottomSelected, 86 | int drawableBottomChecked, 87 | int drawableBottomUnable, 88 | 89 | int drawableLeftWidth, 90 | int drawableLeftHeight, 91 | 92 | int drawableTopWidth, 93 | int drawableTopHeight, 94 | 95 | int drawableRightWidth, 96 | int drawableRightHeight, 97 | 98 | int drawableBottomWidth, 99 | int drawableBottomHeight) { 100 | 101 | mTextView = textView; 102 | 103 | mDrawableLeftNormal = typedArray.getDrawable(drawableLeftNormal); 104 | mDrawableLeftPressed = typedArray.getDrawable(drawableLeftPressed); 105 | mDrawableLeftSelected = typedArray.getDrawable(drawableLeftSelected); 106 | mDrawableLeftChecked = typedArray.getDrawable(drawableLeftChecked); 107 | mDrawableLeftUnable = typedArray.getDrawable(drawableLeftUnable); 108 | 109 | mDrawableTopNormal = typedArray.getDrawable(drawableTopNormal); 110 | mDrawableTopPressed = typedArray.getDrawable(drawableTopPressed); 111 | mDrawableTopSelected = typedArray.getDrawable(drawableTopSelected); 112 | mDrawableTopChecked = typedArray.getDrawable(drawableTopChecked); 113 | mDrawableTopUnable = typedArray.getDrawable(drawableTopUnable); 114 | 115 | mDrawableRightNormal = typedArray.getDrawable(drawableRightNormal); 116 | mDrawableRightPressed = typedArray.getDrawable(drawableRightPressed); 117 | mDrawableRightSelected = typedArray.getDrawable(drawableRightSelected); 118 | mDrawableRightChecked = typedArray.getDrawable(drawableRightChecked); 119 | mDrawableRightUnable = typedArray.getDrawable(drawableRightUnable); 120 | 121 | mDrawableBottomNormal = typedArray.getDrawable(drawableBottomNormal); 122 | mDrawableBottomPressed = typedArray.getDrawable(drawableBottomPressed); 123 | mDrawableBottomSelected = typedArray.getDrawable(drawableBottomSelected); 124 | mDrawableBottomChecked = typedArray.getDrawable(drawableBottomChecked); 125 | mDrawableBottomUnable = typedArray.getDrawable(drawableBottomUnable); 126 | 127 | mDrawableLeftWidth = typedArray.getDimensionPixelOffset(drawableLeftWidth, 0); 128 | mDrawableLeftHeight = typedArray.getDimensionPixelOffset(drawableLeftHeight, 0); 129 | 130 | mDrawableTopWidth = typedArray.getDimensionPixelOffset(drawableTopWidth, 0); 131 | mDrawableTopHeight = typedArray.getDimensionPixelOffset(drawableTopHeight, 0); 132 | 133 | mDrawableRightWidth = typedArray.getDimensionPixelOffset(drawableRightWidth, 0); 134 | mDrawableRightHeight = typedArray.getDimensionPixelOffset(drawableRightHeight, 0); 135 | 136 | mDrawableBottomWidth = typedArray.getDimensionPixelOffset(drawableBottomWidth, 0); 137 | mDrawableBottomHeight = typedArray.getDimensionPixelOffset(drawableBottomHeight, 0); 138 | 139 | updateDrawableLeft(); 140 | updateDrawableTop(); 141 | updateDrawableRight(); 142 | updateDrawableBottom(); 143 | 144 | updateDrawableAndSize(); 145 | } 146 | 147 | public void updateDrawableLeft() { 148 | if (mDrawableLeftNormal == null) { 149 | mCompoundDrawablesLeft = null; 150 | return; 151 | } 152 | 153 | mCompoundDrawablesLeft = new StateListDrawable(); 154 | if (mDrawableLeftUnable != null) { 155 | mCompoundDrawablesLeft.addState(Constant.STATE_0_UNABLE, mDrawableLeftUnable); 156 | } 157 | if (mDrawableLeftPressed != null) { 158 | mCompoundDrawablesLeft.addState(Constant.STATE_1_PRESSED, mDrawableLeftPressed); 159 | } 160 | if (mDrawableLeftSelected != null) { 161 | mCompoundDrawablesLeft.addState(Constant.STATE_2_SELECTED, mDrawableLeftSelected); 162 | } 163 | if (mDrawableLeftChecked != null) { 164 | mCompoundDrawablesLeft.addState(Constant.STATE_3_CHECKED, mDrawableLeftChecked); 165 | } 166 | mCompoundDrawablesLeft.addState(Constant.STATE_4_ENABLED, mDrawableLeftNormal); 167 | mCompoundDrawablesLeft.addState(Constant.STATE_5_NONE, mDrawableLeftNormal); 168 | } 169 | 170 | public void updateDrawableTop() { 171 | if (mDrawableTopNormal == null) { 172 | mCompoundDrawablesTop = null; 173 | return; 174 | } 175 | 176 | mCompoundDrawablesTop = new StateListDrawable(); 177 | if (mDrawableTopUnable != null) { 178 | mCompoundDrawablesTop.addState(Constant.STATE_0_UNABLE, mDrawableTopUnable); 179 | } 180 | if (mDrawableTopPressed != null) { 181 | mCompoundDrawablesTop.addState(Constant.STATE_1_PRESSED, mDrawableTopPressed); 182 | } 183 | if (mDrawableTopSelected != null) { 184 | mCompoundDrawablesTop.addState(Constant.STATE_2_SELECTED, mDrawableTopSelected); 185 | } 186 | if (mDrawableTopChecked != null) { 187 | mCompoundDrawablesTop.addState(Constant.STATE_3_CHECKED, mDrawableTopChecked); 188 | } 189 | mCompoundDrawablesTop.addState(Constant.STATE_4_ENABLED, mDrawableTopNormal); 190 | mCompoundDrawablesTop.addState(Constant.STATE_5_NONE, mDrawableTopNormal); 191 | } 192 | 193 | public void updateDrawableRight() { 194 | if (mDrawableRightNormal == null) { 195 | mCompoundDrawablesRight = null; 196 | return; 197 | } 198 | 199 | mCompoundDrawablesRight = new StateListDrawable(); 200 | if (mDrawableRightUnable != null) { 201 | mCompoundDrawablesRight.addState(Constant.STATE_0_UNABLE, mDrawableRightUnable); 202 | } 203 | if (mDrawableRightPressed != null) { 204 | mCompoundDrawablesRight.addState(Constant.STATE_1_PRESSED, mDrawableRightPressed); 205 | } 206 | if (mDrawableRightSelected != null) { 207 | mCompoundDrawablesRight.addState(Constant.STATE_2_SELECTED, mDrawableRightSelected); 208 | } 209 | if (mDrawableRightChecked != null) { 210 | mCompoundDrawablesRight.addState(Constant.STATE_3_CHECKED, mDrawableRightChecked); 211 | } 212 | mCompoundDrawablesRight.addState(Constant.STATE_4_ENABLED, mDrawableRightNormal); 213 | mCompoundDrawablesRight.addState(Constant.STATE_5_NONE, mDrawableRightNormal); 214 | } 215 | 216 | public void updateDrawableBottom() { 217 | if (mDrawableBottomNormal == null) { 218 | mCompoundDrawablesBottom = null; 219 | return; 220 | } 221 | 222 | mCompoundDrawablesBottom = new StateListDrawable(); 223 | if (mDrawableBottomUnable != null) { 224 | mCompoundDrawablesBottom.addState(Constant.STATE_0_UNABLE, mDrawableBottomUnable); 225 | } 226 | if (mDrawableBottomPressed != null) { 227 | mCompoundDrawablesBottom.addState(Constant.STATE_1_PRESSED, mDrawableBottomPressed); 228 | } 229 | if (mDrawableBottomSelected != null) { 230 | mCompoundDrawablesBottom.addState(Constant.STATE_2_SELECTED, mDrawableBottomSelected); 231 | } 232 | if (mDrawableBottomChecked != null) { 233 | mCompoundDrawablesBottom.addState(Constant.STATE_3_CHECKED, mDrawableBottomChecked); 234 | } 235 | mCompoundDrawablesBottom.addState(Constant.STATE_4_ENABLED, mDrawableBottomNormal); 236 | mCompoundDrawablesBottom.addState(Constant.STATE_5_NONE, mDrawableBottomNormal); 237 | } 238 | 239 | public void updateDrawableAndSize() { 240 | if (mCompoundDrawablesLeft != null) { 241 | if (mDrawableLeftWidth == 0 && mDrawableLeftHeight == 0) { 242 | mCompoundDrawablesLeft.setBounds(0, 0, mCompoundDrawablesLeft.getMinimumWidth(), mCompoundDrawablesLeft.getMinimumHeight()); 243 | } else { 244 | mCompoundDrawablesLeft.setBounds(0, 0, mDrawableLeftWidth, mDrawableLeftHeight); 245 | } 246 | } 247 | 248 | if (mCompoundDrawablesTop != null) { 249 | if (mDrawableTopWidth == 0 && mDrawableTopHeight == 0) { 250 | mCompoundDrawablesTop.setBounds(0, 0, mCompoundDrawablesTop.getMinimumWidth(), mCompoundDrawablesTop.getMinimumHeight()); 251 | } else { 252 | mCompoundDrawablesTop.setBounds(0, 0, mDrawableTopWidth, mDrawableTopHeight); 253 | } 254 | } 255 | 256 | if (mCompoundDrawablesRight != null) { 257 | if (mDrawableRightWidth == 0 && mDrawableRightHeight == 0) { 258 | mCompoundDrawablesRight.setBounds(0, 0, mCompoundDrawablesRight.getMinimumWidth(), mCompoundDrawablesRight.getMinimumHeight()); 259 | } else { 260 | mCompoundDrawablesRight.setBounds(0, 0, mDrawableRightWidth, mDrawableRightHeight); 261 | } 262 | } 263 | 264 | if (mCompoundDrawablesBottom != null) { 265 | if (mDrawableBottomWidth == 0 && mDrawableBottomHeight == 0) { 266 | mCompoundDrawablesBottom.setBounds(0, 0, mCompoundDrawablesBottom.getMinimumWidth(), mCompoundDrawablesBottom.getMinimumHeight()); 267 | } else { 268 | mCompoundDrawablesBottom.setBounds(0, 0, mDrawableBottomWidth, mDrawableBottomHeight); 269 | } 270 | } 271 | 272 | mTextView.setCompoundDrawables(mCompoundDrawablesLeft, mCompoundDrawablesTop, mCompoundDrawablesRight, mCompoundDrawablesBottom); 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/helper/ColorImageViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.helper; 2 | 3 | import android.content.res.TypedArray; 4 | import android.graphics.drawable.Drawable; 5 | import android.graphics.drawable.StateListDrawable; 6 | 7 | import androidx.appcompat.widget.AppCompatImageView; 8 | 9 | import com.wei.android.lib.colorview.utils.Constant; 10 | 11 | /** 12 | * Created by UCCMAWEI on 2017/11/17. 13 | */ 14 | 15 | public class ColorImageViewHelper extends ColorViewHelper { 16 | 17 | // 图片 18 | private Drawable mSrcNormal; 19 | private Drawable mSrcPressed; 20 | private Drawable mSrcSelected; 21 | private Drawable mSrcChecked; 22 | private Drawable mSrcUnable; 23 | 24 | public ColorImageViewHelper(AppCompatImageView imageView, 25 | TypedArray typedArray, 26 | 27 | int srcNormal, 28 | int srcPressed, 29 | int srcSelected, 30 | int srcChecked, 31 | int srcUnable, 32 | 33 | int backgroundColorNormal, 34 | int backgroundColorPressed, 35 | int backgroundColorSelected, 36 | int backgroundColorChecked, 37 | int backgroundColorUnable, 38 | 39 | int backgroundDrawableNormal, 40 | int backgroundDrawablePressed, 41 | int backgroundDrawableSelected, 42 | int backgroundDrawableChecked, 43 | int backgroundDrawableUnable, 44 | 45 | int gradientOrientationNormal, 46 | int gradientOrientationPressed, 47 | int gradientOrientationSelected, 48 | int gradientOrientationChecked, 49 | int gradientOrientationUnable, 50 | 51 | int gradientCenterXNormal, 52 | int gradientCenterXPressed, 53 | int gradientCenterXSelected, 54 | int gradientCenterXChecked, 55 | int gradientCenterXUnable, 56 | 57 | int gradientCenterYNormal, 58 | int gradientCenterYPressed, 59 | int gradientCenterYSelected, 60 | int gradientCenterYChecked, 61 | int gradientCenterYUnable, 62 | 63 | int gradientStartColorNormal, 64 | int gradientStartColorPressed, 65 | int gradientStartColorSelected, 66 | int gradientStartColorChecked, 67 | int gradientStartColorUnable, 68 | 69 | int gradientCenterColorNormal, 70 | int gradientCenterColorPressed, 71 | int gradientCenterColorSelected, 72 | int gradientCenterColorChecked, 73 | int gradientCenterColorUnable, 74 | 75 | int gradientEndColorNormal, 76 | int gradientEndColorPressed, 77 | int gradientEndColorSelected, 78 | int gradientEndColorChecked, 79 | int gradientEndColorUnable, 80 | 81 | int gradientRadiusNormal, 82 | int gradientRadiusPressed, 83 | int gradientRadiusSelected, 84 | int gradientRadiusChecked, 85 | int gradientRadiusUnable, 86 | 87 | int gradientTypeNormal, 88 | int gradientTypePressed, 89 | int gradientTypeSelected, 90 | int gradientTypeChecked, 91 | int gradientTypeUnable, 92 | 93 | int cornerRadiusNormal, 94 | int cornerRadiusPressed, 95 | int cornerRadiusSelected, 96 | int cornerRadiusChecked, 97 | int cornerRadiusUnable, 98 | 99 | int cornerRadiusTopLeftNormal, 100 | int cornerRadiusTopLeftPressed, 101 | int cornerRadiusTopLeftSelected, 102 | int cornerRadiusTopLeftChecked, 103 | int cornerRadiusTopLeftUnable, 104 | 105 | int cornerRadiusTopRightNormal, 106 | int cornerRadiusTopRightPressed, 107 | int cornerRadiusTopRightSelected, 108 | int cornerRadiusTopRightChecked, 109 | int cornerRadiusTopRightUnable, 110 | 111 | int cornerRadiusBottomLeftNormal, 112 | int cornerRadiusBottomLeftPressed, 113 | int cornerRadiusBottomLeftSelected, 114 | int cornerRadiusBottomLeftChecked, 115 | int cornerRadiusBottomLeftUnable, 116 | 117 | int cornerRadiusBottomRightNormal, 118 | int cornerRadiusBottomRightPressed, 119 | int cornerRadiusBottomRightSelected, 120 | int cornerRadiusBottomRightChecked, 121 | int cornerRadiusBottomRightUnable, 122 | 123 | int borderWidthNormal, 124 | int borderWidthPressed, 125 | int borderWidthSelected, 126 | int borderWidthChecked, 127 | int borderWidthUnable, 128 | 129 | int borderDashWidthNormal, 130 | int borderDashWidthPressed, 131 | int borderDashWidthSelected, 132 | int borderDashWidthChecked, 133 | int borderDashWidthUnable, 134 | 135 | int borderDashGapNormal, 136 | int borderDashGapPressed, 137 | int borderDashGapSelected, 138 | int borderDashGapChecked, 139 | int borderDashGapUnable, 140 | 141 | int borderColorNormal, 142 | int borderColorPressed, 143 | int borderColorSelected, 144 | int borderColorChecked, 145 | int borderColorUnable, 146 | 147 | int backgroundColorTintPressed) { 148 | 149 | super(imageView, 150 | typedArray, 151 | 152 | backgroundColorNormal, 153 | backgroundColorPressed, 154 | backgroundColorSelected, 155 | backgroundColorChecked, 156 | backgroundColorUnable, 157 | 158 | backgroundDrawableNormal, 159 | backgroundDrawablePressed, 160 | backgroundDrawableSelected, 161 | backgroundDrawableChecked, 162 | backgroundDrawableUnable, 163 | 164 | gradientOrientationNormal, 165 | gradientOrientationPressed, 166 | gradientOrientationSelected, 167 | gradientOrientationChecked, 168 | gradientOrientationUnable, 169 | 170 | gradientCenterXNormal, 171 | gradientCenterXPressed, 172 | gradientCenterXSelected, 173 | gradientCenterXChecked, 174 | gradientCenterXUnable, 175 | 176 | gradientCenterYNormal, 177 | gradientCenterYPressed, 178 | gradientCenterYSelected, 179 | gradientCenterYChecked, 180 | gradientCenterYUnable, 181 | 182 | gradientStartColorNormal, 183 | gradientStartColorPressed, 184 | gradientStartColorSelected, 185 | gradientStartColorChecked, 186 | gradientStartColorUnable, 187 | 188 | gradientCenterColorNormal, 189 | gradientCenterColorPressed, 190 | gradientCenterColorSelected, 191 | gradientCenterColorChecked, 192 | gradientCenterColorUnable, 193 | 194 | gradientEndColorNormal, 195 | gradientEndColorPressed, 196 | gradientEndColorSelected, 197 | gradientEndColorChecked, 198 | gradientEndColorUnable, 199 | 200 | gradientRadiusNormal, 201 | gradientRadiusPressed, 202 | gradientRadiusSelected, 203 | gradientRadiusChecked, 204 | gradientRadiusUnable, 205 | 206 | gradientTypeNormal, 207 | gradientTypePressed, 208 | gradientTypeSelected, 209 | gradientTypeChecked, 210 | gradientTypeUnable, 211 | 212 | cornerRadiusNormal, 213 | cornerRadiusPressed, 214 | cornerRadiusSelected, 215 | cornerRadiusChecked, 216 | cornerRadiusUnable, 217 | 218 | cornerRadiusTopLeftNormal, 219 | cornerRadiusTopLeftPressed, 220 | cornerRadiusTopLeftSelected, 221 | cornerRadiusTopLeftChecked, 222 | cornerRadiusTopLeftUnable, 223 | 224 | cornerRadiusTopRightNormal, 225 | cornerRadiusTopRightPressed, 226 | cornerRadiusTopRightSelected, 227 | cornerRadiusTopRightChecked, 228 | cornerRadiusTopRightUnable, 229 | 230 | cornerRadiusBottomLeftNormal, 231 | cornerRadiusBottomLeftPressed, 232 | cornerRadiusBottomLeftSelected, 233 | cornerRadiusBottomLeftChecked, 234 | cornerRadiusBottomLeftUnable, 235 | 236 | cornerRadiusBottomRightNormal, 237 | cornerRadiusBottomRightPressed, 238 | cornerRadiusBottomRightSelected, 239 | cornerRadiusBottomRightChecked, 240 | cornerRadiusBottomRightUnable, 241 | 242 | borderWidthNormal, 243 | borderWidthPressed, 244 | borderWidthSelected, 245 | borderWidthChecked, 246 | borderWidthUnable, 247 | 248 | borderDashWidthNormal, 249 | borderDashWidthPressed, 250 | borderDashWidthSelected, 251 | borderDashWidthChecked, 252 | borderDashWidthUnable, 253 | 254 | borderDashGapNormal, 255 | borderDashGapPressed, 256 | borderDashGapSelected, 257 | borderDashGapChecked, 258 | borderDashGapUnable, 259 | 260 | borderColorNormal, 261 | borderColorPressed, 262 | borderColorSelected, 263 | borderColorChecked, 264 | borderColorUnable, 265 | 266 | backgroundColorTintPressed); 267 | 268 | mSrcNormal = typedArray.getDrawable(srcNormal); 269 | mSrcPressed = typedArray.getDrawable(srcPressed); 270 | mSrcSelected = typedArray.getDrawable(srcSelected); 271 | mSrcChecked = typedArray.getDrawable(srcChecked); 272 | mSrcUnable = typedArray.getDrawable(srcUnable); 273 | 274 | if (mSrcPressed == null && mSrcNormal != null) { 275 | mSrcPressed = typedArray.getDrawable(srcNormal); 276 | } 277 | 278 | if (mSrcSelected == null && mSrcNormal != null) { 279 | mSrcSelected = typedArray.getDrawable(srcNormal); 280 | } 281 | 282 | if (mSrcChecked == null && mSrcNormal != null) { 283 | mSrcChecked = typedArray.getDrawable(srcNormal); 284 | } 285 | 286 | if (mSrcUnable == null && mSrcNormal != null) { 287 | mSrcUnable = typedArray.getDrawable(srcNormal); 288 | } 289 | 290 | updateSrcDrawable(); 291 | } 292 | 293 | // 设置图片 294 | private void updateSrcDrawable() { 295 | StateListDrawable stateListDrawable = new StateListDrawable(); 296 | 297 | if (mSrcUnable != null) { 298 | stateListDrawable.addState(Constant.STATE_0_UNABLE, mSrcUnable); 299 | } 300 | 301 | if (mSrcPressed != null) { 302 | stateListDrawable.addState(Constant.STATE_1_PRESSED, mSrcPressed); 303 | } 304 | 305 | if (mSrcSelected != null) { 306 | stateListDrawable.addState(Constant.STATE_2_SELECTED, mSrcSelected); 307 | } 308 | 309 | if (mSrcChecked != null) { 310 | stateListDrawable.addState(Constant.STATE_3_CHECKED, mSrcChecked); 311 | } 312 | 313 | if (mSrcNormal != null) { 314 | stateListDrawable.addState(Constant.STATE_4_ENABLED, mSrcNormal); 315 | } 316 | 317 | if (mSrcNormal != null) { 318 | stateListDrawable.addState(Constant.STATE_5_NONE, mSrcNormal); 319 | } 320 | 321 | mView.setImageDrawable(stateListDrawable); 322 | } 323 | 324 | // GET SET 325 | public Drawable getSrcNormal() { 326 | return mSrcNormal; 327 | } 328 | 329 | public void setSrcNormal(Drawable srcNormal) { 330 | if (mSrcNormal != srcNormal) { 331 | mSrcNormal = srcNormal; 332 | updateSrcDrawable(); 333 | } 334 | } 335 | 336 | public Drawable getSrcPressed() { 337 | return mSrcPressed; 338 | } 339 | 340 | public void setSrcPressed(Drawable srcPressed) { 341 | if (mSrcPressed != srcPressed) { 342 | mSrcPressed = srcPressed; 343 | updateSrcDrawable(); 344 | } 345 | } 346 | 347 | public Drawable getSrcSelected() { 348 | return mSrcSelected; 349 | } 350 | 351 | public void setSrcSelected(Drawable srcSelected) { 352 | if (mSrcSelected != srcSelected) { 353 | mSrcSelected = srcSelected; 354 | updateSrcDrawable(); 355 | } 356 | } 357 | 358 | public Drawable getSrcChecked() { 359 | return mSrcChecked; 360 | } 361 | 362 | public void setSrcChecked(Drawable srcChecked) { 363 | if (mSrcChecked != srcChecked) { 364 | mSrcChecked = srcChecked; 365 | updateSrcDrawable(); 366 | } 367 | } 368 | 369 | public Drawable getSrcUnable() { 370 | return mSrcUnable; 371 | } 372 | 373 | public void setSrcUnable(Drawable srcUnable) { 374 | if (mSrcUnable != srcUnable) { 375 | mSrcUnable = srcUnable; 376 | updateSrcDrawable(); 377 | } 378 | } 379 | } 380 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/helper/ColorTextViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.helper; 2 | 3 | import android.content.res.ColorStateList; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Paint; 6 | import android.graphics.drawable.Drawable; 7 | import android.widget.TextView; 8 | 9 | import com.wei.android.lib.colorview.drawable.CompoundDrawables; 10 | import com.wei.android.lib.colorview.utils.Constant; 11 | 12 | 13 | /** 14 | * Created by UCCMAWEI on 2017/11/17. 15 | */ 16 | 17 | public class ColorTextViewHelper extends ColorViewHelper { 18 | 19 | // 文字颜色 20 | private int mTextColorNormal; 21 | private int mTextColorPressed; 22 | private int mTextColorSelected; 23 | private int mTextColorChecked; 24 | private int mTextColorUnable; 25 | 26 | // 文字加粗 27 | private float mTextStrokeWidth; 28 | 29 | // 文字颜色 30 | private int mTextColorHintNormal; 31 | private int mTextColorHintPressed; 32 | private int mTextColorHintSelected; 33 | private int mTextColorHintChecked; 34 | private int mTextColorHintUnable; 35 | 36 | // 边缘图标 37 | private final CompoundDrawables mCompoundDrawables; 38 | 39 | public ColorTextViewHelper(TextView textView, 40 | TypedArray typedArray, 41 | 42 | int currentTextColor, 43 | int textColorNormal, 44 | int textColorPressed, 45 | int textColorSelected, 46 | int textColorChecked, 47 | int textColorUnable, 48 | 49 | int textStrokeWidth, 50 | 51 | int currentTextColorHint, 52 | int textColorHintNormal, 53 | int textColorHintPressed, 54 | int textColorHintSelected, 55 | int textColorHintChecked, 56 | int textColorHintUnable, 57 | 58 | int backgroundColorNormal, 59 | int backgroundColorPressed, 60 | int backgroundColorSelected, 61 | int backgroundColorChecked, 62 | int backgroundColorUnable, 63 | 64 | int backgroundDrawableNormal, 65 | int backgroundDrawablePressed, 66 | int backgroundDrawableSelected, 67 | int backgroundDrawableChecked, 68 | int backgroundDrawableUnable, 69 | 70 | int gradientOrientationNormal, 71 | int gradientOrientationPressed, 72 | int gradientOrientationSelected, 73 | int gradientOrientationChecked, 74 | int gradientOrientationUnable, 75 | 76 | int gradientCenterXNormal, 77 | int gradientCenterXPressed, 78 | int gradientCenterXSelected, 79 | int gradientCenterXChecked, 80 | int gradientCenterXUnable, 81 | 82 | int gradientCenterYNormal, 83 | int gradientCenterYPressed, 84 | int gradientCenterYSelected, 85 | int gradientCenterYChecked, 86 | int gradientCenterYUnable, 87 | 88 | int gradientStartColorNormal, 89 | int gradientStartColorPressed, 90 | int gradientStartColorSelected, 91 | int gradientStartColorChecked, 92 | int gradientStartColorUnable, 93 | 94 | int gradientCenterColorNormal, 95 | int gradientCenterColorPressed, 96 | int gradientCenterColorSelected, 97 | int gradientCenterColorChecked, 98 | int gradientCenterColorUnable, 99 | 100 | int gradientEndColorNormal, 101 | int gradientEndColorPressed, 102 | int gradientEndColorSelected, 103 | int gradientEndColorChecked, 104 | int gradientEndColorUnable, 105 | 106 | int gradientRadiusNormal, 107 | int gradientRadiusPressed, 108 | int gradientRadiusSelected, 109 | int gradientRadiusChecked, 110 | int gradientRadiusUnable, 111 | 112 | int gradientTypeNormal, 113 | int gradientTypePressed, 114 | int gradientTypeSelected, 115 | int gradientTypeChecked, 116 | int gradientTypeUnable, 117 | 118 | int cornerRadiusNormal, 119 | int cornerRadiusPressed, 120 | int cornerRadiusSelected, 121 | int cornerRadiusChecked, 122 | int cornerRadiusUnable, 123 | 124 | int cornerRadiusTopLeftNormal, 125 | int cornerRadiusTopLeftPressed, 126 | int cornerRadiusTopLeftSelected, 127 | int cornerRadiusTopLeftChecked, 128 | int cornerRadiusTopLeftUnable, 129 | 130 | int cornerRadiusTopRightNormal, 131 | int cornerRadiusTopRightPressed, 132 | int cornerRadiusTopRightSelected, 133 | int cornerRadiusTopRightChecked, 134 | int cornerRadiusTopRightUnable, 135 | 136 | int cornerRadiusBottomLeftNormal, 137 | int cornerRadiusBottomLeftPressed, 138 | int cornerRadiusBottomLeftSelected, 139 | int cornerRadiusBottomLeftChecked, 140 | int cornerRadiusBottomLeftUnable, 141 | 142 | int cornerRadiusBottomRightNormal, 143 | int cornerRadiusBottomRightPressed, 144 | int cornerRadiusBottomRightSelected, 145 | int cornerRadiusBottomRightChecked, 146 | int cornerRadiusBottomRightUnable, 147 | 148 | int borderWidthNormal, 149 | int borderWidthPressed, 150 | int borderWidthSelected, 151 | int borderWidthChecked, 152 | int borderWidthUnable, 153 | 154 | int borderDashWidthNormal, 155 | int borderDashWidthPressed, 156 | int borderDashWidthSelected, 157 | int borderDashWidthChecked, 158 | int borderDashWidthUnable, 159 | 160 | int borderDashGapNormal, 161 | int borderDashGapPressed, 162 | int borderDashGapSelected, 163 | int borderDashGapChecked, 164 | int borderDashGapUnable, 165 | 166 | int borderColorNormal, 167 | int borderColorPressed, 168 | int borderColorSelected, 169 | int borderColorChecked, 170 | int borderColorUnable, 171 | 172 | int drawableLeftNormal, 173 | int drawableLeftPressed, 174 | int drawableLeftSelected, 175 | int drawableLeftChecked, 176 | int drawableLeftUnable, 177 | 178 | int drawableTopNormal, 179 | int drawableTopPressed, 180 | int drawableTopSelected, 181 | int drawableTopChecked, 182 | int drawableTopUnable, 183 | 184 | int drawableRightNormal, 185 | int drawableRightPressed, 186 | int drawableRightSelected, 187 | int drawableRightChecked, 188 | int drawableRightUnable, 189 | 190 | int drawableBottomNormal, 191 | int drawableBottomPressed, 192 | int drawableBottomSelected, 193 | int drawableBottomChecked, 194 | int drawableBottomUnable, 195 | 196 | int drawableLeftWidth, 197 | int drawableLeftHeight, 198 | 199 | int drawableTopWidth, 200 | int drawableTopHeight, 201 | 202 | int drawableRightWidth, 203 | int drawableRightHeight, 204 | 205 | int drawableBottomWidth, 206 | int drawableBottomHeight, 207 | 208 | int backgroundColorTintPressed) { 209 | 210 | super(textView, 211 | typedArray, 212 | 213 | backgroundColorNormal, 214 | backgroundColorPressed, 215 | backgroundColorSelected, 216 | backgroundColorChecked, 217 | backgroundColorUnable, 218 | 219 | backgroundDrawableNormal, 220 | backgroundDrawablePressed, 221 | backgroundDrawableSelected, 222 | backgroundDrawableChecked, 223 | backgroundDrawableUnable, 224 | 225 | gradientOrientationNormal, 226 | gradientOrientationPressed, 227 | gradientOrientationSelected, 228 | gradientOrientationChecked, 229 | gradientOrientationUnable, 230 | 231 | gradientCenterXNormal, 232 | gradientCenterXPressed, 233 | gradientCenterXSelected, 234 | gradientCenterXChecked, 235 | gradientCenterXUnable, 236 | 237 | gradientCenterYNormal, 238 | gradientCenterYPressed, 239 | gradientCenterYSelected, 240 | gradientCenterYChecked, 241 | gradientCenterYUnable, 242 | 243 | gradientStartColorNormal, 244 | gradientStartColorPressed, 245 | gradientStartColorSelected, 246 | gradientStartColorChecked, 247 | gradientStartColorUnable, 248 | 249 | gradientCenterColorNormal, 250 | gradientCenterColorPressed, 251 | gradientCenterColorSelected, 252 | gradientCenterColorChecked, 253 | gradientCenterColorUnable, 254 | 255 | gradientEndColorNormal, 256 | gradientEndColorPressed, 257 | gradientEndColorSelected, 258 | gradientEndColorChecked, 259 | gradientEndColorUnable, 260 | 261 | gradientRadiusNormal, 262 | gradientRadiusPressed, 263 | gradientRadiusSelected, 264 | gradientRadiusChecked, 265 | gradientRadiusUnable, 266 | 267 | gradientTypeNormal, 268 | gradientTypePressed, 269 | gradientTypeSelected, 270 | gradientTypeChecked, 271 | gradientTypeUnable, 272 | 273 | cornerRadiusNormal, 274 | cornerRadiusPressed, 275 | cornerRadiusSelected, 276 | cornerRadiusChecked, 277 | cornerRadiusUnable, 278 | 279 | cornerRadiusTopLeftNormal, 280 | cornerRadiusTopLeftPressed, 281 | cornerRadiusTopLeftSelected, 282 | cornerRadiusTopLeftChecked, 283 | cornerRadiusTopLeftUnable, 284 | 285 | cornerRadiusTopRightNormal, 286 | cornerRadiusTopRightPressed, 287 | cornerRadiusTopRightSelected, 288 | cornerRadiusTopRightChecked, 289 | cornerRadiusTopRightUnable, 290 | 291 | cornerRadiusBottomLeftNormal, 292 | cornerRadiusBottomLeftPressed, 293 | cornerRadiusBottomLeftSelected, 294 | cornerRadiusBottomLeftChecked, 295 | cornerRadiusBottomLeftUnable, 296 | 297 | cornerRadiusBottomRightNormal, 298 | cornerRadiusBottomRightPressed, 299 | cornerRadiusBottomRightSelected, 300 | cornerRadiusBottomRightChecked, 301 | cornerRadiusBottomRightUnable, 302 | 303 | borderWidthNormal, 304 | borderWidthPressed, 305 | borderWidthSelected, 306 | borderWidthChecked, 307 | borderWidthUnable, 308 | 309 | borderDashWidthNormal, 310 | borderDashWidthPressed, 311 | borderDashWidthSelected, 312 | borderDashWidthChecked, 313 | borderDashWidthUnable, 314 | 315 | borderDashGapNormal, 316 | borderDashGapPressed, 317 | borderDashGapSelected, 318 | borderDashGapChecked, 319 | borderDashGapUnable, 320 | 321 | borderColorNormal, 322 | borderColorPressed, 323 | borderColorSelected, 324 | borderColorChecked, 325 | borderColorUnable, 326 | 327 | backgroundColorTintPressed); 328 | 329 | mTextColorNormal = typedArray.getColor(textColorNormal, currentTextColor); 330 | mTextColorPressed = typedArray.getColor(textColorPressed, mTextColorNormal); 331 | mTextColorSelected = typedArray.getColor(textColorSelected, mTextColorNormal); 332 | mTextColorChecked = typedArray.getColor(textColorChecked, mTextColorNormal); 333 | mTextColorUnable = typedArray.getColor(textColorUnable, mTextColorNormal); 334 | 335 | mTextStrokeWidth = typedArray.getFloat(textStrokeWidth, -1); 336 | 337 | mTextColorHintNormal = typedArray.getColor(textColorHintNormal, currentTextColorHint); 338 | mTextColorHintPressed = typedArray.getColor(textColorHintPressed, mTextColorHintNormal); 339 | mTextColorHintSelected = typedArray.getColor(textColorHintSelected, mTextColorHintNormal); 340 | mTextColorHintChecked = typedArray.getColor(textColorHintChecked, mTextColorHintNormal); 341 | mTextColorHintUnable = typedArray.getColor(textColorHintUnable, mTextColorHintNormal); 342 | 343 | mCompoundDrawables = new CompoundDrawables(textView, 344 | typedArray, 345 | 346 | drawableLeftNormal, 347 | drawableLeftPressed, 348 | drawableLeftSelected, 349 | drawableLeftChecked, 350 | drawableLeftUnable, 351 | 352 | drawableTopNormal, 353 | drawableTopPressed, 354 | drawableTopSelected, 355 | drawableTopChecked, 356 | drawableTopUnable, 357 | 358 | drawableRightNormal, 359 | drawableRightPressed, 360 | drawableRightSelected, 361 | drawableRightChecked, 362 | drawableRightUnable, 363 | 364 | drawableBottomNormal, 365 | drawableBottomPressed, 366 | drawableBottomSelected, 367 | drawableBottomChecked, 368 | drawableBottomUnable, 369 | 370 | drawableLeftWidth, 371 | drawableLeftHeight, 372 | 373 | drawableTopWidth, 374 | drawableTopHeight, 375 | 376 | drawableRightWidth, 377 | drawableRightHeight, 378 | 379 | drawableBottomWidth, 380 | drawableBottomHeight); 381 | 382 | updateTextColor(); 383 | updateTextStrokeWidth(); 384 | updateTextColorHint(); 385 | } 386 | 387 | // 内容文字颜色 388 | private void updateTextColor() { 389 | int[] colors = {mTextColorUnable, mTextColorPressed, mTextColorSelected, mTextColorChecked, mTextColorNormal, mTextColorNormal}; 390 | mView.setTextColor(new ColorStateList(Constant.STATE_ARRAY, colors)); 391 | } 392 | 393 | // 加粗 394 | private void updateTextStrokeWidth() { 395 | if (mTextStrokeWidth >= 0) { 396 | mView.getPaint().setStyle(Paint.Style.FILL_AND_STROKE); 397 | mView.getPaint().setStrokeWidth(mTextStrokeWidth); 398 | } 399 | } 400 | 401 | // 提示文字颜色 402 | private void updateTextColorHint() { 403 | int[] colors = {mTextColorHintUnable, mTextColorHintPressed, mTextColorHintSelected, mTextColorHintChecked, mTextColorHintNormal, mTextColorHintNormal}; 404 | mView.setHintTextColor(new ColorStateList(Constant.STATE_ARRAY, colors)); 405 | } 406 | 407 | // GET SET 408 | public int getTextColorNormal() { 409 | return mTextColorNormal; 410 | } 411 | 412 | public void setTextColorNormal(int textColorNormal) { 413 | if (mTextColorNormal != textColorNormal) { 414 | mTextColorNormal = textColorNormal; 415 | updateTextColor(); 416 | } 417 | } 418 | 419 | public int getTextColorPressed() { 420 | return mTextColorPressed; 421 | } 422 | 423 | public void setTextColorPressed(int textColorPressed) { 424 | if (mTextColorPressed != textColorPressed) { 425 | mTextColorPressed = textColorPressed; 426 | updateTextColor(); 427 | } 428 | } 429 | 430 | public int getTextColorSelected() { 431 | return mTextColorSelected; 432 | } 433 | 434 | public void setTextColorSelected(int textColorSelected) { 435 | if (mTextColorSelected != textColorSelected) { 436 | mTextColorSelected = textColorSelected; 437 | updateTextColor(); 438 | } 439 | } 440 | 441 | public int getTextColorChecked() { 442 | return mTextColorChecked; 443 | } 444 | 445 | public void setTextColorChecked(int textColorChecked) { 446 | if (mTextColorChecked != textColorChecked) { 447 | mTextColorChecked = textColorChecked; 448 | updateTextColor(); 449 | } 450 | } 451 | 452 | public int getTextColorUnable() { 453 | return mTextColorUnable; 454 | } 455 | 456 | public void setTextColorUnable(int textColorUnable) { 457 | if (mTextColorUnable != textColorUnable) { 458 | mTextColorUnable = textColorUnable; 459 | updateTextColor(); 460 | } 461 | } 462 | 463 | public int getTextColorHintNormal() { 464 | return mTextColorHintNormal; 465 | } 466 | 467 | public void setTextColorHintNormal(int textColorHintNormal) { 468 | if (mTextColorHintNormal != textColorHintNormal) { 469 | mTextColorHintNormal = textColorHintNormal; 470 | updateTextColorHint(); 471 | } 472 | } 473 | 474 | public int getTextColorHintPressed() { 475 | return mTextColorHintPressed; 476 | } 477 | 478 | public void setTextColorHintPressed(int textColorHintPressed) { 479 | if (mTextColorHintPressed != textColorHintPressed) { 480 | mTextColorHintPressed = textColorHintPressed; 481 | updateTextColorHint(); 482 | } 483 | } 484 | 485 | public int getTextColorHintSelected() { 486 | return mTextColorHintSelected; 487 | } 488 | 489 | public void setTextColorHintSelected(int textColorHintSelected) { 490 | if (mTextColorHintSelected != textColorHintSelected) { 491 | mTextColorHintSelected = textColorHintSelected; 492 | updateTextColorHint(); 493 | } 494 | } 495 | 496 | public int getTextColorHintChecked() { 497 | return mTextColorHintChecked; 498 | } 499 | 500 | public void setTextColorHintChecked(int textColorHintChecked) { 501 | if (mTextColorHintChecked != textColorHintChecked) { 502 | mTextColorHintChecked = textColorHintChecked; 503 | updateTextColorHint(); 504 | } 505 | } 506 | 507 | public int getTextColorHintUnable() { 508 | return mTextColorHintUnable; 509 | } 510 | 511 | public void setTextColorHintUnable(int textColorHintUnable) { 512 | if (mTextColorHintUnable != textColorHintUnable) { 513 | mTextColorHintUnable = textColorHintUnable; 514 | updateTextColorHint(); 515 | } 516 | } 517 | 518 | // GET SET 519 | public Drawable getDrawableLeftNormal() { 520 | return mCompoundDrawables.mDrawableLeftNormal; 521 | } 522 | 523 | public void setDrawableLeftNormal(Drawable drawableLeftNormal) { 524 | if (mCompoundDrawables.mDrawableLeftNormal != drawableLeftNormal) { 525 | mCompoundDrawables.mDrawableLeftNormal = drawableLeftNormal; 526 | mCompoundDrawables.updateDrawableLeft(); 527 | mCompoundDrawables.updateDrawableAndSize(); 528 | } 529 | } 530 | 531 | public Drawable getDrawableLeftPressed() { 532 | return mCompoundDrawables.mDrawableLeftPressed; 533 | } 534 | 535 | public void setDrawableLeftPressed(Drawable drawableLeftPressed) { 536 | if (mCompoundDrawables.mDrawableLeftPressed != drawableLeftPressed) { 537 | mCompoundDrawables.mDrawableLeftPressed = drawableLeftPressed; 538 | mCompoundDrawables.updateDrawableLeft(); 539 | mCompoundDrawables.updateDrawableAndSize(); 540 | } 541 | } 542 | 543 | public Drawable getDrawableLeftSelected() { 544 | return mCompoundDrawables.mDrawableLeftSelected; 545 | } 546 | 547 | public void setDrawableLeftSelected(Drawable drawableLeftSelected) { 548 | if (mCompoundDrawables.mDrawableLeftSelected != drawableLeftSelected) { 549 | mCompoundDrawables.mDrawableLeftSelected = drawableLeftSelected; 550 | mCompoundDrawables.updateDrawableLeft(); 551 | mCompoundDrawables.updateDrawableAndSize(); 552 | } 553 | } 554 | 555 | public Drawable getDrawableLeftChecked() { 556 | return mCompoundDrawables.mDrawableLeftChecked; 557 | } 558 | 559 | public void setDrawableLeftChecked(Drawable drawableLeftChecked) { 560 | if (mCompoundDrawables.mDrawableLeftChecked != drawableLeftChecked) { 561 | mCompoundDrawables.mDrawableLeftChecked = drawableLeftChecked; 562 | mCompoundDrawables.updateDrawableLeft(); 563 | mCompoundDrawables.updateDrawableAndSize(); 564 | } 565 | } 566 | 567 | public Drawable getDrawableLeftUnable() { 568 | return mCompoundDrawables.mDrawableLeftUnable; 569 | } 570 | 571 | public void setDrawableLeftUnable(Drawable drawableLeftUnable) { 572 | if (mCompoundDrawables.mDrawableLeftUnable != drawableLeftUnable) { 573 | mCompoundDrawables.mDrawableLeftUnable = drawableLeftUnable; 574 | mCompoundDrawables.updateDrawableLeft(); 575 | mCompoundDrawables.updateDrawableAndSize(); 576 | } 577 | } 578 | 579 | public Drawable getDrawableTopNormal() { 580 | return mCompoundDrawables.mDrawableTopNormal; 581 | } 582 | 583 | public void setDrawableTopNormal(Drawable drawableTopNormal) { 584 | if (mCompoundDrawables.mDrawableTopNormal != drawableTopNormal) { 585 | mCompoundDrawables.mDrawableTopNormal = drawableTopNormal; 586 | mCompoundDrawables.updateDrawableTop(); 587 | mCompoundDrawables.updateDrawableAndSize(); 588 | } 589 | } 590 | 591 | public Drawable getDrawableTopPressed() { 592 | return mCompoundDrawables.mDrawableTopPressed; 593 | } 594 | 595 | public void setDrawableTopPressed(Drawable drawableTopPressed) { 596 | if (mCompoundDrawables.mDrawableTopPressed != drawableTopPressed) { 597 | mCompoundDrawables.mDrawableTopPressed = drawableTopPressed; 598 | mCompoundDrawables.updateDrawableTop(); 599 | mCompoundDrawables.updateDrawableAndSize(); 600 | } 601 | } 602 | 603 | public Drawable getDrawableTopSelected() { 604 | return mCompoundDrawables.mDrawableTopSelected; 605 | } 606 | 607 | public void setDrawableTopSelected(Drawable drawableTopSelected) { 608 | if (mCompoundDrawables.mDrawableTopSelected != drawableTopSelected) { 609 | mCompoundDrawables.mDrawableTopSelected = drawableTopSelected; 610 | mCompoundDrawables.updateDrawableTop(); 611 | mCompoundDrawables.updateDrawableAndSize(); 612 | } 613 | } 614 | 615 | public Drawable getDrawableTopChecked() { 616 | return mCompoundDrawables.mDrawableTopChecked; 617 | } 618 | 619 | public void setDrawableTopChecked(Drawable drawableTopChecked) { 620 | if (mCompoundDrawables.mDrawableTopChecked != drawableTopChecked) { 621 | mCompoundDrawables.mDrawableTopChecked = drawableTopChecked; 622 | mCompoundDrawables.updateDrawableTop(); 623 | mCompoundDrawables.updateDrawableAndSize(); 624 | } 625 | } 626 | 627 | public Drawable getDrawableTopUnable() { 628 | return mCompoundDrawables.mDrawableTopUnable; 629 | } 630 | 631 | public void setDrawableTopUnable(Drawable drawableTopUnable) { 632 | if (mCompoundDrawables.mDrawableTopUnable != drawableTopUnable) { 633 | mCompoundDrawables.mDrawableTopUnable = drawableTopUnable; 634 | mCompoundDrawables.updateDrawableTop(); 635 | mCompoundDrawables.updateDrawableAndSize(); 636 | } 637 | } 638 | 639 | public Drawable getDrawableRightNormal() { 640 | return mCompoundDrawables.mDrawableRightNormal; 641 | } 642 | 643 | public void setDrawableRightNormal(Drawable drawableRightNormal) { 644 | if (mCompoundDrawables.mDrawableRightNormal != drawableRightNormal) { 645 | mCompoundDrawables.mDrawableRightNormal = drawableRightNormal; 646 | mCompoundDrawables.updateDrawableRight(); 647 | mCompoundDrawables.updateDrawableAndSize(); 648 | } 649 | } 650 | 651 | public Drawable getDrawableRightPressed() { 652 | return mCompoundDrawables.mDrawableRightPressed; 653 | } 654 | 655 | public void setDrawableRightPressed(Drawable drawableRightPressed) { 656 | if (mCompoundDrawables.mDrawableRightPressed != drawableRightPressed) { 657 | mCompoundDrawables.mDrawableRightPressed = drawableRightPressed; 658 | mCompoundDrawables.updateDrawableRight(); 659 | mCompoundDrawables.updateDrawableAndSize(); 660 | } 661 | } 662 | 663 | public Drawable getDrawableRightSelected() { 664 | return mCompoundDrawables.mDrawableRightSelected; 665 | } 666 | 667 | public void setDrawableRightSelected(Drawable drawableRightSelected) { 668 | if (mCompoundDrawables.mDrawableRightSelected != drawableRightSelected) { 669 | mCompoundDrawables.mDrawableRightSelected = drawableRightSelected; 670 | mCompoundDrawables.updateDrawableRight(); 671 | mCompoundDrawables.updateDrawableAndSize(); 672 | } 673 | } 674 | 675 | public Drawable getDrawableRightChecked() { 676 | return mCompoundDrawables.mDrawableRightChecked; 677 | } 678 | 679 | public void setDrawableRightChecked(Drawable drawableRightChecked) { 680 | if (mCompoundDrawables.mDrawableRightChecked != drawableRightChecked) { 681 | mCompoundDrawables.mDrawableRightChecked = drawableRightChecked; 682 | mCompoundDrawables.updateDrawableRight(); 683 | mCompoundDrawables.updateDrawableAndSize(); 684 | } 685 | } 686 | 687 | public Drawable getDrawableRightUnable() { 688 | return mCompoundDrawables.mDrawableRightUnable; 689 | } 690 | 691 | public void setDrawableRightUnable(Drawable drawableRightUnable) { 692 | if (mCompoundDrawables.mDrawableRightUnable != drawableRightUnable) { 693 | mCompoundDrawables.mDrawableRightUnable = drawableRightUnable; 694 | mCompoundDrawables.updateDrawableRight(); 695 | mCompoundDrawables.updateDrawableAndSize(); 696 | } 697 | } 698 | 699 | public Drawable getDrawableBottomNormal() { 700 | return mCompoundDrawables.mDrawableBottomNormal; 701 | } 702 | 703 | public void setDrawableBottomNormal(Drawable drawableBottomNormal) { 704 | if (mCompoundDrawables.mDrawableBottomNormal != drawableBottomNormal) { 705 | mCompoundDrawables.mDrawableBottomNormal = drawableBottomNormal; 706 | mCompoundDrawables.updateDrawableBottom(); 707 | mCompoundDrawables.updateDrawableAndSize(); 708 | } 709 | } 710 | 711 | public Drawable getDrawableBottomPressed() { 712 | return mCompoundDrawables.mDrawableBottomPressed; 713 | } 714 | 715 | public void setDrawableBottomPressed(Drawable drawableBottomPressed) { 716 | if (mCompoundDrawables.mDrawableBottomPressed != drawableBottomPressed) { 717 | mCompoundDrawables.mDrawableBottomPressed = drawableBottomPressed; 718 | mCompoundDrawables.updateDrawableBottom(); 719 | mCompoundDrawables.updateDrawableAndSize(); 720 | } 721 | } 722 | 723 | public Drawable getDrawableBottomSelected() { 724 | return mCompoundDrawables.mDrawableBottomSelected; 725 | } 726 | 727 | public void setDrawableBottomSelected(Drawable drawableBottomSelected) { 728 | if (mCompoundDrawables.mDrawableBottomSelected != drawableBottomSelected) { 729 | mCompoundDrawables.mDrawableBottomSelected = drawableBottomSelected; 730 | mCompoundDrawables.updateDrawableBottom(); 731 | mCompoundDrawables.updateDrawableAndSize(); 732 | } 733 | } 734 | 735 | public Drawable getDrawableBottomChecked() { 736 | return mCompoundDrawables.mDrawableBottomChecked; 737 | } 738 | 739 | public void setDrawableBottomChecked(Drawable drawableBottomChecked) { 740 | if (mCompoundDrawables.mDrawableBottomChecked != drawableBottomChecked) { 741 | mCompoundDrawables.mDrawableBottomChecked = drawableBottomChecked; 742 | mCompoundDrawables.updateDrawableBottom(); 743 | mCompoundDrawables.updateDrawableAndSize(); 744 | } 745 | } 746 | 747 | public Drawable getDrawableBottomUnable() { 748 | return mCompoundDrawables.mDrawableBottomUnable; 749 | } 750 | 751 | public void setDrawableBottomUnable(Drawable drawableBottomUnable) { 752 | if (mCompoundDrawables.mDrawableBottomUnable != drawableBottomUnable) { 753 | mCompoundDrawables.mDrawableBottomUnable = drawableBottomUnable; 754 | mCompoundDrawables.updateDrawableBottom(); 755 | mCompoundDrawables.updateDrawableAndSize(); 756 | } 757 | } 758 | 759 | public int getDrawableLeftWidth() { 760 | return mCompoundDrawables.mDrawableLeftWidth; 761 | } 762 | 763 | public void setDrawableLeftWidth(int drawableLeftWidth) { 764 | if (mCompoundDrawables.mDrawableLeftWidth != drawableLeftWidth) { 765 | mCompoundDrawables.mDrawableLeftWidth = drawableLeftWidth; 766 | mCompoundDrawables.updateDrawableAndSize(); 767 | } 768 | } 769 | 770 | public int getDrawableLeftHeight() { 771 | return mCompoundDrawables.mDrawableLeftHeight; 772 | } 773 | 774 | public void setDrawableLeftHeight(int drawableLeftHeight) { 775 | if (mCompoundDrawables.mDrawableLeftHeight != drawableLeftHeight) { 776 | mCompoundDrawables.mDrawableLeftHeight = drawableLeftHeight; 777 | mCompoundDrawables.updateDrawableAndSize(); 778 | } 779 | } 780 | 781 | public int getDrawableRightWidth() { 782 | return mCompoundDrawables.mDrawableRightWidth; 783 | } 784 | 785 | public void setDrawableRightWidth(int drawableRightWidth) { 786 | if (mCompoundDrawables.mDrawableRightWidth != drawableRightWidth) { 787 | mCompoundDrawables.mDrawableRightWidth = drawableRightWidth; 788 | mCompoundDrawables.updateDrawableAndSize(); 789 | } 790 | } 791 | 792 | public int getDrawableRightHeight() { 793 | return mCompoundDrawables.mDrawableRightHeight; 794 | } 795 | 796 | public void setDrawableRightHeight(int drawableRightHeight) { 797 | if (mCompoundDrawables.mDrawableRightHeight != drawableRightHeight) { 798 | mCompoundDrawables.mDrawableRightHeight = drawableRightHeight; 799 | mCompoundDrawables.updateDrawableAndSize(); 800 | } 801 | } 802 | 803 | public int getDrawableTopWidth() { 804 | return mCompoundDrawables.mDrawableTopWidth; 805 | } 806 | 807 | public void setDrawableTopWidth(int drawableTopWidth) { 808 | if (mCompoundDrawables.mDrawableTopWidth != drawableTopWidth) { 809 | mCompoundDrawables.mDrawableTopWidth = drawableTopWidth; 810 | mCompoundDrawables.updateDrawableAndSize(); 811 | } 812 | } 813 | 814 | public int getDrawableTopHeight() { 815 | return mCompoundDrawables.mDrawableTopHeight; 816 | } 817 | 818 | public void setDrawableTopHeight(int drawableTopHeight) { 819 | if (mCompoundDrawables.mDrawableTopHeight != drawableTopHeight) { 820 | mCompoundDrawables.mDrawableTopHeight = drawableTopHeight; 821 | mCompoundDrawables.updateDrawableAndSize(); 822 | } 823 | } 824 | 825 | public int getDrawableBottomWidth() { 826 | return mCompoundDrawables.mDrawableBottomWidth; 827 | } 828 | 829 | public void setDrawableBottomWidth(int drawableBottomWidth) { 830 | if (mCompoundDrawables.mDrawableBottomWidth != drawableBottomWidth) { 831 | mCompoundDrawables.mDrawableBottomWidth = drawableBottomWidth; 832 | mCompoundDrawables.updateDrawableAndSize(); 833 | } 834 | } 835 | 836 | public int getDrawableBottomHeight() { 837 | return mCompoundDrawables.mDrawableBottomHeight; 838 | } 839 | 840 | public void setDrawableBottomHeight(int drawableBottomHeight) { 841 | if (mCompoundDrawables.mDrawableBottomHeight != drawableBottomHeight) { 842 | mCompoundDrawables.mDrawableBottomHeight = drawableBottomHeight; 843 | mCompoundDrawables.updateDrawableAndSize(); 844 | } 845 | } 846 | 847 | public float getTextStrokeWidth() { 848 | return mTextStrokeWidth; 849 | } 850 | 851 | public void setTextStrokeWidth(float textStrokeWidth) { 852 | if (mTextStrokeWidth != textStrokeWidth) { 853 | mTextStrokeWidth = textStrokeWidth; 854 | updateTextStrokeWidth(); 855 | } 856 | } 857 | } 858 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/utils/Constant.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.utils; 2 | 3 | /** 4 | * Created by UCCMAWEI on 2018/12/27. 5 | *

6 | * 常量都在这边定义 7 | */ 8 | 9 | public class Constant { 10 | 11 | // 整个库支持的五种状态 12 | public static final int[] STATE_0_UNABLE = {-android.R.attr.state_enabled}; 13 | public static final int[] STATE_1_PRESSED = {android.R.attr.state_pressed}; 14 | public static final int[] STATE_2_SELECTED = {android.R.attr.state_selected}; 15 | public static final int[] STATE_3_CHECKED = {android.R.attr.state_checked}; 16 | public static final int[] STATE_4_ENABLED = {android.R.attr.state_enabled}; 17 | public static final int[] STATE_5_NONE = {}; 18 | 19 | // 整个库支持的五种状态 20 | public static final int STATE_INDEX_COUNT = 5; 21 | public static final int STATE_INDEX_NORMAL = 0; 22 | public static final int STATE_INDEX_PRESSED = 1; 23 | public static final int STATE_INDEX_SELECTED = 2; 24 | public static final int STATE_INDEX_CHECKED = 3; 25 | public static final int STATE_INDEX_UNABLE = 4; 26 | 27 | // 整个库支持的五种状态 28 | public static final int[][] STATE_ARRAY = {STATE_0_UNABLE, STATE_1_PRESSED, STATE_2_SELECTED, STATE_3_CHECKED, STATE_4_ENABLED, STATE_5_NONE}; 29 | 30 | // 渐变支持八个方向 31 | public static final int GRADIENT_ORIENTATION_T_B = 1; 32 | public static final int GRADIENT_ORIENTATION_TR_BL = 2; 33 | public static final int GRADIENT_ORIENTATION_R_L = 3; 34 | public static final int GRADIENT_ORIENTATION_BR_TL = 4; 35 | public static final int GRADIENT_ORIENTATION_B_T = 5; 36 | public static final int GRADIENT_ORIENTATION_BL_TR = 6; 37 | public static final int GRADIENT_ORIENTATION_L_R = 7; 38 | public static final int GRADIENT_ORIENTATION_TL_BR = 8; 39 | 40 | // 渐变支持3种类型 41 | public static final int GRADIENT_TYPE_NONE = 0; 42 | public static final int GRADIENT_TYPE_LINEAR = 1; 43 | public static final int GRADIENT_TYPE_RADIAL = 2; 44 | public static final int GRADIENT_TYPE_SWEEP = 3; 45 | 46 | // 默认从中间开始 47 | public static final float CENTER_XY = 0.5f; 48 | } 49 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorButton.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.ColorStateList; 5 | import android.content.res.TypedArray; 6 | import android.graphics.drawable.Drawable; 7 | import android.util.AttributeSet; 8 | 9 | import androidx.annotation.ColorInt; 10 | import androidx.annotation.DrawableRes; 11 | import androidx.appcompat.widget.AppCompatButton; 12 | 13 | import com.wei.android.lib.colorview.R; 14 | import com.wei.android.lib.colorview.helper.ColorTextViewHelper; 15 | 16 | /** 17 | * Created by UCCMAWEI on 2017/11/17. 18 | */ 19 | 20 | public class ColorButton extends AppCompatButton { 21 | 22 | private ColorTextViewHelper mColorTextViewHelper; 23 | 24 | public ColorButton(Context context) { 25 | super(context); 26 | init(null); 27 | } 28 | 29 | public ColorButton(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | init(attrs); 32 | } 33 | 34 | public ColorButton(Context context, AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | init(attrs); 37 | } 38 | 39 | private void init(AttributeSet attrs) { 40 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorButton); 41 | 42 | mColorTextViewHelper = new ColorTextViewHelper(this, 43 | typedArray, 44 | 45 | getCurrentTextColor(), 46 | R.styleable.ColorButton_textColorNormal, 47 | R.styleable.ColorButton_textColorPressed, 48 | R.styleable.ColorButton_textColorSelected, 49 | R.styleable.ColorButton_textColorChecked, 50 | R.styleable.ColorButton_textColorUnable, 51 | 52 | R.styleable.ColorButton_textStrokeWidth, 53 | 54 | getCurrentHintTextColor(), 55 | R.styleable.ColorButton_textColorHintNormal, 56 | R.styleable.ColorButton_textColorHintPressed, 57 | R.styleable.ColorButton_textColorHintSelected, 58 | R.styleable.ColorButton_textColorHintChecked, 59 | R.styleable.ColorButton_textColorHintUnable, 60 | 61 | R.styleable.ColorButton_backgroundColorNormal, 62 | R.styleable.ColorButton_backgroundColorPressed, 63 | R.styleable.ColorButton_backgroundColorSelected, 64 | R.styleable.ColorButton_backgroundColorChecked, 65 | R.styleable.ColorButton_backgroundColorUnable, 66 | 67 | R.styleable.ColorButton_backgroundDrawableNormal, 68 | R.styleable.ColorButton_backgroundDrawablePressed, 69 | R.styleable.ColorButton_backgroundDrawableSelected, 70 | R.styleable.ColorButton_backgroundDrawableChecked, 71 | R.styleable.ColorButton_backgroundDrawableUnable, 72 | 73 | R.styleable.ColorButton_gradientOrientationNormal, 74 | R.styleable.ColorButton_gradientOrientationPressed, 75 | R.styleable.ColorButton_gradientOrientationSelected, 76 | R.styleable.ColorButton_gradientOrientationChecked, 77 | R.styleable.ColorButton_gradientOrientationUnable, 78 | 79 | R.styleable.ColorButton_gradientCenterXNormal, 80 | R.styleable.ColorButton_gradientCenterXPressed, 81 | R.styleable.ColorButton_gradientCenterXSelected, 82 | R.styleable.ColorButton_gradientCenterXChecked, 83 | R.styleable.ColorButton_gradientCenterXUnable, 84 | 85 | R.styleable.ColorButton_gradientCenterYNormal, 86 | R.styleable.ColorButton_gradientCenterYPressed, 87 | R.styleable.ColorButton_gradientCenterYSelected, 88 | R.styleable.ColorButton_gradientCenterYChecked, 89 | R.styleable.ColorButton_gradientCenterYUnable, 90 | 91 | R.styleable.ColorButton_gradientStartColorNormal, 92 | R.styleable.ColorButton_gradientStartColorPressed, 93 | R.styleable.ColorButton_gradientStartColorSelected, 94 | R.styleable.ColorButton_gradientStartColorChecked, 95 | R.styleable.ColorButton_gradientStartColorUnable, 96 | 97 | R.styleable.ColorButton_gradientCenterColorNormal, 98 | R.styleable.ColorButton_gradientCenterColorPressed, 99 | R.styleable.ColorButton_gradientCenterColorSelected, 100 | R.styleable.ColorButton_gradientCenterColorChecked, 101 | R.styleable.ColorButton_gradientCenterColorUnable, 102 | 103 | R.styleable.ColorButton_gradientEndColorNormal, 104 | R.styleable.ColorButton_gradientEndColorPressed, 105 | R.styleable.ColorButton_gradientEndColorSelected, 106 | R.styleable.ColorButton_gradientEndColorChecked, 107 | R.styleable.ColorButton_gradientEndColorUnable, 108 | 109 | R.styleable.ColorButton_gradientRadiusNormal, 110 | R.styleable.ColorButton_gradientRadiusPressed, 111 | R.styleable.ColorButton_gradientRadiusSelected, 112 | R.styleable.ColorButton_gradientRadiusChecked, 113 | R.styleable.ColorButton_gradientRadiusUnable, 114 | 115 | R.styleable.ColorButton_gradientTypeNormal, 116 | R.styleable.ColorButton_gradientTypePressed, 117 | R.styleable.ColorButton_gradientTypeSelected, 118 | R.styleable.ColorButton_gradientTypeChecked, 119 | R.styleable.ColorButton_gradientTypeUnable, 120 | 121 | R.styleable.ColorButton_cornerRadiusNormal, 122 | R.styleable.ColorButton_cornerRadiusPressed, 123 | R.styleable.ColorButton_cornerRadiusSelected, 124 | R.styleable.ColorButton_cornerRadiusChecked, 125 | R.styleable.ColorButton_cornerRadiusUnable, 126 | 127 | R.styleable.ColorButton_cornerRadiusTopLeftNormal, 128 | R.styleable.ColorButton_cornerRadiusTopLeftPressed, 129 | R.styleable.ColorButton_cornerRadiusTopLeftSelected, 130 | R.styleable.ColorButton_cornerRadiusTopLeftChecked, 131 | R.styleable.ColorButton_cornerRadiusTopLeftUnable, 132 | 133 | R.styleable.ColorButton_cornerRadiusTopRightNormal, 134 | R.styleable.ColorButton_cornerRadiusTopRightPressed, 135 | R.styleable.ColorButton_cornerRadiusTopRightSelected, 136 | R.styleable.ColorButton_cornerRadiusTopRightChecked, 137 | R.styleable.ColorButton_cornerRadiusTopRightUnable, 138 | 139 | R.styleable.ColorButton_cornerRadiusBottomLeftNormal, 140 | R.styleable.ColorButton_cornerRadiusBottomLeftPressed, 141 | R.styleable.ColorButton_cornerRadiusBottomLeftSelected, 142 | R.styleable.ColorButton_cornerRadiusBottomLeftChecked, 143 | R.styleable.ColorButton_cornerRadiusBottomLeftUnable, 144 | 145 | R.styleable.ColorButton_cornerRadiusBottomRightNormal, 146 | R.styleable.ColorButton_cornerRadiusBottomRightPressed, 147 | R.styleable.ColorButton_cornerRadiusBottomRightSelected, 148 | R.styleable.ColorButton_cornerRadiusBottomRightChecked, 149 | R.styleable.ColorButton_cornerRadiusBottomRightUnable, 150 | 151 | R.styleable.ColorButton_borderWidthNormal, 152 | R.styleable.ColorButton_borderWidthPressed, 153 | R.styleable.ColorButton_borderWidthSelected, 154 | R.styleable.ColorButton_borderWidthChecked, 155 | R.styleable.ColorButton_borderWidthUnable, 156 | 157 | R.styleable.ColorButton_borderDashWidthNormal, 158 | R.styleable.ColorButton_borderDashWidthPressed, 159 | R.styleable.ColorButton_borderDashWidthSelected, 160 | R.styleable.ColorButton_borderDashWidthChecked, 161 | R.styleable.ColorButton_borderDashWidthUnable, 162 | 163 | R.styleable.ColorButton_borderDashGapNormal, 164 | R.styleable.ColorButton_borderDashGapPressed, 165 | R.styleable.ColorButton_borderDashGapSelected, 166 | R.styleable.ColorButton_borderDashGapChecked, 167 | R.styleable.ColorButton_borderDashGapUnable, 168 | 169 | R.styleable.ColorButton_borderColorNormal, 170 | R.styleable.ColorButton_borderColorPressed, 171 | R.styleable.ColorButton_borderColorSelected, 172 | R.styleable.ColorButton_borderColorChecked, 173 | R.styleable.ColorButton_borderColorUnable, 174 | 175 | R.styleable.ColorButton_drawableLeftNormal, 176 | R.styleable.ColorButton_drawableLeftPressed, 177 | R.styleable.ColorButton_drawableLeftSelected, 178 | R.styleable.ColorButton_drawableLeftChecked, 179 | R.styleable.ColorButton_drawableLeftUnable, 180 | 181 | R.styleable.ColorButton_drawableTopNormal, 182 | R.styleable.ColorButton_drawableTopPressed, 183 | R.styleable.ColorButton_drawableTopSelected, 184 | R.styleable.ColorButton_drawableTopChecked, 185 | R.styleable.ColorButton_drawableTopUnable, 186 | 187 | R.styleable.ColorButton_drawableRightNormal, 188 | R.styleable.ColorButton_drawableRightPressed, 189 | R.styleable.ColorButton_drawableRightSelected, 190 | R.styleable.ColorButton_drawableRightChecked, 191 | R.styleable.ColorButton_drawableRightUnable, 192 | 193 | R.styleable.ColorButton_drawableBottomNormal, 194 | R.styleable.ColorButton_drawableBottomPressed, 195 | R.styleable.ColorButton_drawableBottomSelected, 196 | R.styleable.ColorButton_drawableBottomChecked, 197 | R.styleable.ColorButton_drawableBottomUnable, 198 | 199 | R.styleable.ColorButton_drawableLeftWidth, 200 | R.styleable.ColorButton_drawableLeftHeight, 201 | 202 | R.styleable.ColorButton_drawableTopWidth, 203 | R.styleable.ColorButton_drawableTopHeight, 204 | 205 | R.styleable.ColorButton_drawableRightWidth, 206 | R.styleable.ColorButton_drawableRightHeight, 207 | 208 | R.styleable.ColorButton_drawableBottomWidth, 209 | R.styleable.ColorButton_drawableBottomHeight, 210 | 211 | R.styleable.ColorButton_backgroundTintPressed); 212 | 213 | typedArray.recycle(); 214 | } 215 | 216 | public ColorTextViewHelper getColorHelper() { 217 | return mColorTextViewHelper; 218 | } 219 | 220 | @Deprecated 221 | @Override 222 | public void setBackground(Drawable background) { 223 | super.setBackground(background); 224 | } 225 | 226 | @Deprecated 227 | @Override 228 | public void setBackgroundColor(@ColorInt int color) { 229 | super.setBackgroundColor(color); 230 | } 231 | 232 | @Deprecated 233 | @Override 234 | public void setBackgroundResource(@DrawableRes int resId) { 235 | super.setBackgroundResource(resId); 236 | } 237 | 238 | @Deprecated 239 | @Override 240 | public void setTextColor(@ColorInt int color) { 241 | super.setTextColor(color); 242 | } 243 | 244 | @Deprecated 245 | @Override 246 | public void setTextColor(ColorStateList colors) { 247 | super.setTextColor(colors); 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorEditText.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.ColorStateList; 5 | import android.content.res.TypedArray; 6 | import android.graphics.drawable.Drawable; 7 | import android.util.AttributeSet; 8 | 9 | import androidx.annotation.ColorInt; 10 | import androidx.annotation.DrawableRes; 11 | import androidx.appcompat.widget.AppCompatEditText; 12 | 13 | import com.wei.android.lib.colorview.R; 14 | import com.wei.android.lib.colorview.helper.ColorTextViewHelper; 15 | 16 | /** 17 | * Created by UCCMAWEI on 2017/11/17. 18 | */ 19 | 20 | public class ColorEditText extends AppCompatEditText { 21 | 22 | private ColorTextViewHelper mColorTextViewHelper; 23 | 24 | public ColorEditText(Context context) { 25 | super(context); 26 | init(null); 27 | } 28 | 29 | public ColorEditText(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | init(attrs); 32 | } 33 | 34 | public ColorEditText(Context context, AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | init(attrs); 37 | } 38 | 39 | private void init(AttributeSet attrs) { 40 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorEditText); 41 | 42 | mColorTextViewHelper = new ColorTextViewHelper(this, 43 | typedArray, 44 | 45 | getCurrentTextColor(), 46 | R.styleable.ColorEditText_textColorNormal, 47 | R.styleable.ColorEditText_textColorPressed, 48 | R.styleable.ColorEditText_textColorSelected, 49 | R.styleable.ColorEditText_textColorChecked, 50 | R.styleable.ColorEditText_textColorUnable, 51 | 52 | R.styleable.ColorEditText_textStrokeWidth, 53 | 54 | getCurrentHintTextColor(), 55 | R.styleable.ColorEditText_textColorHintNormal, 56 | R.styleable.ColorEditText_textColorHintPressed, 57 | R.styleable.ColorEditText_textColorHintSelected, 58 | R.styleable.ColorEditText_textColorHintChecked, 59 | R.styleable.ColorEditText_textColorHintUnable, 60 | 61 | R.styleable.ColorEditText_backgroundColorNormal, 62 | R.styleable.ColorEditText_backgroundColorPressed, 63 | R.styleable.ColorEditText_backgroundColorSelected, 64 | R.styleable.ColorEditText_backgroundColorChecked, 65 | R.styleable.ColorEditText_backgroundColorUnable, 66 | 67 | R.styleable.ColorEditText_backgroundDrawableNormal, 68 | R.styleable.ColorEditText_backgroundDrawablePressed, 69 | R.styleable.ColorEditText_backgroundDrawableSelected, 70 | R.styleable.ColorEditText_backgroundDrawableChecked, 71 | R.styleable.ColorEditText_backgroundDrawableUnable, 72 | 73 | R.styleable.ColorEditText_gradientOrientationNormal, 74 | R.styleable.ColorEditText_gradientOrientationPressed, 75 | R.styleable.ColorEditText_gradientOrientationSelected, 76 | R.styleable.ColorEditText_gradientOrientationChecked, 77 | R.styleable.ColorEditText_gradientOrientationUnable, 78 | 79 | R.styleable.ColorEditText_gradientCenterXNormal, 80 | R.styleable.ColorEditText_gradientCenterXPressed, 81 | R.styleable.ColorEditText_gradientCenterXSelected, 82 | R.styleable.ColorEditText_gradientCenterXChecked, 83 | R.styleable.ColorEditText_gradientCenterXUnable, 84 | 85 | R.styleable.ColorEditText_gradientCenterYNormal, 86 | R.styleable.ColorEditText_gradientCenterYPressed, 87 | R.styleable.ColorEditText_gradientCenterYSelected, 88 | R.styleable.ColorEditText_gradientCenterYChecked, 89 | R.styleable.ColorEditText_gradientCenterYUnable, 90 | 91 | R.styleable.ColorEditText_gradientStartColorNormal, 92 | R.styleable.ColorEditText_gradientStartColorPressed, 93 | R.styleable.ColorEditText_gradientStartColorSelected, 94 | R.styleable.ColorEditText_gradientStartColorChecked, 95 | R.styleable.ColorEditText_gradientStartColorUnable, 96 | 97 | R.styleable.ColorEditText_gradientCenterColorNormal, 98 | R.styleable.ColorEditText_gradientCenterColorPressed, 99 | R.styleable.ColorEditText_gradientCenterColorSelected, 100 | R.styleable.ColorEditText_gradientCenterColorChecked, 101 | R.styleable.ColorEditText_gradientCenterColorUnable, 102 | 103 | R.styleable.ColorEditText_gradientEndColorNormal, 104 | R.styleable.ColorEditText_gradientEndColorPressed, 105 | R.styleable.ColorEditText_gradientEndColorSelected, 106 | R.styleable.ColorEditText_gradientEndColorChecked, 107 | R.styleable.ColorEditText_gradientEndColorUnable, 108 | 109 | R.styleable.ColorEditText_gradientRadiusNormal, 110 | R.styleable.ColorEditText_gradientRadiusPressed, 111 | R.styleable.ColorEditText_gradientRadiusSelected, 112 | R.styleable.ColorEditText_gradientRadiusChecked, 113 | R.styleable.ColorEditText_gradientRadiusUnable, 114 | 115 | R.styleable.ColorEditText_gradientTypeNormal, 116 | R.styleable.ColorEditText_gradientTypePressed, 117 | R.styleable.ColorEditText_gradientTypeSelected, 118 | R.styleable.ColorEditText_gradientTypeChecked, 119 | R.styleable.ColorEditText_gradientTypeUnable, 120 | 121 | R.styleable.ColorEditText_cornerRadiusNormal, 122 | R.styleable.ColorEditText_cornerRadiusPressed, 123 | R.styleable.ColorEditText_cornerRadiusSelected, 124 | R.styleable.ColorEditText_cornerRadiusChecked, 125 | R.styleable.ColorEditText_cornerRadiusUnable, 126 | 127 | R.styleable.ColorEditText_cornerRadiusTopLeftNormal, 128 | R.styleable.ColorEditText_cornerRadiusTopLeftPressed, 129 | R.styleable.ColorEditText_cornerRadiusTopLeftSelected, 130 | R.styleable.ColorEditText_cornerRadiusTopLeftChecked, 131 | R.styleable.ColorEditText_cornerRadiusTopLeftUnable, 132 | 133 | R.styleable.ColorEditText_cornerRadiusTopRightNormal, 134 | R.styleable.ColorEditText_cornerRadiusTopRightPressed, 135 | R.styleable.ColorEditText_cornerRadiusTopRightSelected, 136 | R.styleable.ColorEditText_cornerRadiusTopRightChecked, 137 | R.styleable.ColorEditText_cornerRadiusTopRightUnable, 138 | 139 | R.styleable.ColorEditText_cornerRadiusBottomLeftNormal, 140 | R.styleable.ColorEditText_cornerRadiusBottomLeftPressed, 141 | R.styleable.ColorEditText_cornerRadiusBottomLeftSelected, 142 | R.styleable.ColorEditText_cornerRadiusBottomLeftChecked, 143 | R.styleable.ColorEditText_cornerRadiusBottomLeftUnable, 144 | 145 | R.styleable.ColorEditText_cornerRadiusBottomRightNormal, 146 | R.styleable.ColorEditText_cornerRadiusBottomRightPressed, 147 | R.styleable.ColorEditText_cornerRadiusBottomRightSelected, 148 | R.styleable.ColorEditText_cornerRadiusBottomRightChecked, 149 | R.styleable.ColorEditText_cornerRadiusBottomRightUnable, 150 | 151 | R.styleable.ColorEditText_borderWidthNormal, 152 | R.styleable.ColorEditText_borderWidthPressed, 153 | R.styleable.ColorEditText_borderWidthSelected, 154 | R.styleable.ColorEditText_borderWidthChecked, 155 | R.styleable.ColorEditText_borderWidthUnable, 156 | 157 | R.styleable.ColorEditText_borderDashWidthNormal, 158 | R.styleable.ColorEditText_borderDashWidthPressed, 159 | R.styleable.ColorEditText_borderDashWidthSelected, 160 | R.styleable.ColorEditText_borderDashWidthChecked, 161 | R.styleable.ColorEditText_borderDashWidthUnable, 162 | 163 | R.styleable.ColorEditText_borderDashGapNormal, 164 | R.styleable.ColorEditText_borderDashGapPressed, 165 | R.styleable.ColorEditText_borderDashGapSelected, 166 | R.styleable.ColorEditText_borderDashGapChecked, 167 | R.styleable.ColorEditText_borderDashGapUnable, 168 | 169 | R.styleable.ColorEditText_borderColorNormal, 170 | R.styleable.ColorEditText_borderColorPressed, 171 | R.styleable.ColorEditText_borderColorSelected, 172 | R.styleable.ColorEditText_borderColorChecked, 173 | R.styleable.ColorEditText_borderColorUnable, 174 | 175 | R.styleable.ColorEditText_drawableLeftNormal, 176 | R.styleable.ColorEditText_drawableLeftPressed, 177 | R.styleable.ColorEditText_drawableLeftSelected, 178 | R.styleable.ColorEditText_drawableLeftChecked, 179 | R.styleable.ColorEditText_drawableLeftUnable, 180 | 181 | R.styleable.ColorEditText_drawableTopNormal, 182 | R.styleable.ColorEditText_drawableTopPressed, 183 | R.styleable.ColorEditText_drawableTopSelected, 184 | R.styleable.ColorEditText_drawableTopChecked, 185 | R.styleable.ColorEditText_drawableTopUnable, 186 | 187 | R.styleable.ColorEditText_drawableRightNormal, 188 | R.styleable.ColorEditText_drawableRightPressed, 189 | R.styleable.ColorEditText_drawableRightSelected, 190 | R.styleable.ColorEditText_drawableRightChecked, 191 | R.styleable.ColorEditText_drawableRightUnable, 192 | 193 | R.styleable.ColorEditText_drawableBottomNormal, 194 | R.styleable.ColorEditText_drawableBottomPressed, 195 | R.styleable.ColorEditText_drawableBottomSelected, 196 | R.styleable.ColorEditText_drawableBottomChecked, 197 | R.styleable.ColorEditText_drawableBottomUnable, 198 | 199 | R.styleable.ColorEditText_drawableLeftWidth, 200 | R.styleable.ColorEditText_drawableLeftHeight, 201 | 202 | R.styleable.ColorEditText_drawableTopWidth, 203 | R.styleable.ColorEditText_drawableTopHeight, 204 | 205 | R.styleable.ColorEditText_drawableRightWidth, 206 | R.styleable.ColorEditText_drawableRightHeight, 207 | 208 | R.styleable.ColorEditText_drawableBottomWidth, 209 | R.styleable.ColorEditText_drawableBottomHeight, 210 | 211 | R.styleable.ColorEditText_backgroundTintPressed); 212 | 213 | typedArray.recycle(); 214 | } 215 | 216 | public ColorTextViewHelper getColorHelper() { 217 | return mColorTextViewHelper; 218 | } 219 | 220 | @Deprecated 221 | @Override 222 | public void setBackground(Drawable background) { 223 | super.setBackground(background); 224 | } 225 | 226 | @Deprecated 227 | @Override 228 | public void setBackgroundColor(@ColorInt int color) { 229 | super.setBackgroundColor(color); 230 | } 231 | 232 | @Deprecated 233 | @Override 234 | public void setBackgroundResource(@DrawableRes int resId) { 235 | super.setBackgroundResource(resId); 236 | } 237 | 238 | @Deprecated 239 | @Override 240 | public void setTextColor(@ColorInt int color) { 241 | super.setTextColor(color); 242 | } 243 | 244 | @Deprecated 245 | @Override 246 | public void setTextColor(ColorStateList colors) { 247 | super.setTextColor(colors); 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorFrameLayout.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.widget.FrameLayout; 10 | 11 | import androidx.annotation.ColorInt; 12 | import androidx.annotation.DrawableRes; 13 | import androidx.annotation.NonNull; 14 | import androidx.annotation.Nullable; 15 | import androidx.annotation.RequiresApi; 16 | 17 | import com.wei.android.lib.colorview.R; 18 | import com.wei.android.lib.colorview.helper.ColorViewHelper; 19 | 20 | /** 21 | * Created by UCCMAWEI on 2017/11/17. 22 | */ 23 | 24 | public class ColorFrameLayout extends FrameLayout { 25 | 26 | private ColorViewHelper mColorViewHelper; 27 | 28 | public ColorFrameLayout(@NonNull Context context) { 29 | super(context); 30 | init(null); 31 | } 32 | 33 | public ColorFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { 34 | super(context, attrs); 35 | init(attrs); 36 | } 37 | 38 | public ColorFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 39 | super(context, attrs, defStyleAttr); 40 | init(attrs); 41 | } 42 | 43 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 44 | public ColorFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 45 | super(context, attrs, defStyleAttr, defStyleRes); 46 | init(attrs); 47 | } 48 | 49 | private void init(AttributeSet attrs) { 50 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorFrameLayout); 51 | 52 | mColorViewHelper = new ColorViewHelper(this, 53 | typedArray, 54 | 55 | R.styleable.ColorFrameLayout_backgroundColorNormal, 56 | R.styleable.ColorFrameLayout_backgroundColorPressed, 57 | R.styleable.ColorFrameLayout_backgroundColorSelected, 58 | R.styleable.ColorFrameLayout_backgroundColorChecked, 59 | R.styleable.ColorFrameLayout_backgroundColorUnable, 60 | 61 | R.styleable.ColorFrameLayout_backgroundDrawableNormal, 62 | R.styleable.ColorFrameLayout_backgroundDrawablePressed, 63 | R.styleable.ColorFrameLayout_backgroundDrawableSelected, 64 | R.styleable.ColorFrameLayout_backgroundDrawableChecked, 65 | R.styleable.ColorFrameLayout_backgroundDrawableUnable, 66 | 67 | R.styleable.ColorFrameLayout_gradientOrientationNormal, 68 | R.styleable.ColorFrameLayout_gradientOrientationPressed, 69 | R.styleable.ColorFrameLayout_gradientOrientationSelected, 70 | R.styleable.ColorFrameLayout_gradientOrientationChecked, 71 | R.styleable.ColorFrameLayout_gradientOrientationUnable, 72 | 73 | R.styleable.ColorFrameLayout_gradientCenterXNormal, 74 | R.styleable.ColorFrameLayout_gradientCenterXPressed, 75 | R.styleable.ColorFrameLayout_gradientCenterXSelected, 76 | R.styleable.ColorFrameLayout_gradientCenterXChecked, 77 | R.styleable.ColorFrameLayout_gradientCenterXUnable, 78 | 79 | R.styleable.ColorFrameLayout_gradientCenterYNormal, 80 | R.styleable.ColorFrameLayout_gradientCenterYPressed, 81 | R.styleable.ColorFrameLayout_gradientCenterYSelected, 82 | R.styleable.ColorFrameLayout_gradientCenterYChecked, 83 | R.styleable.ColorFrameLayout_gradientCenterYUnable, 84 | 85 | R.styleable.ColorFrameLayout_gradientStartColorNormal, 86 | R.styleable.ColorFrameLayout_gradientStartColorPressed, 87 | R.styleable.ColorFrameLayout_gradientStartColorSelected, 88 | R.styleable.ColorFrameLayout_gradientStartColorChecked, 89 | R.styleable.ColorFrameLayout_gradientStartColorUnable, 90 | 91 | R.styleable.ColorFrameLayout_gradientCenterColorNormal, 92 | R.styleable.ColorFrameLayout_gradientCenterColorPressed, 93 | R.styleable.ColorFrameLayout_gradientCenterColorSelected, 94 | R.styleable.ColorFrameLayout_gradientCenterColorChecked, 95 | R.styleable.ColorFrameLayout_gradientCenterColorUnable, 96 | 97 | R.styleable.ColorFrameLayout_gradientEndColorNormal, 98 | R.styleable.ColorFrameLayout_gradientEndColorPressed, 99 | R.styleable.ColorFrameLayout_gradientEndColorSelected, 100 | R.styleable.ColorFrameLayout_gradientEndColorChecked, 101 | R.styleable.ColorFrameLayout_gradientEndColorUnable, 102 | 103 | R.styleable.ColorFrameLayout_gradientRadiusNormal, 104 | R.styleable.ColorFrameLayout_gradientRadiusPressed, 105 | R.styleable.ColorFrameLayout_gradientRadiusSelected, 106 | R.styleable.ColorFrameLayout_gradientRadiusChecked, 107 | R.styleable.ColorFrameLayout_gradientRadiusUnable, 108 | 109 | R.styleable.ColorFrameLayout_gradientTypeNormal, 110 | R.styleable.ColorFrameLayout_gradientTypePressed, 111 | R.styleable.ColorFrameLayout_gradientTypeSelected, 112 | R.styleable.ColorFrameLayout_gradientTypeChecked, 113 | R.styleable.ColorFrameLayout_gradientTypeUnable, 114 | 115 | R.styleable.ColorFrameLayout_cornerRadiusNormal, 116 | R.styleable.ColorFrameLayout_cornerRadiusPressed, 117 | R.styleable.ColorFrameLayout_cornerRadiusSelected, 118 | R.styleable.ColorFrameLayout_cornerRadiusChecked, 119 | R.styleable.ColorFrameLayout_cornerRadiusUnable, 120 | 121 | R.styleable.ColorFrameLayout_cornerRadiusTopLeftNormal, 122 | R.styleable.ColorFrameLayout_cornerRadiusTopLeftPressed, 123 | R.styleable.ColorFrameLayout_cornerRadiusTopLeftSelected, 124 | R.styleable.ColorFrameLayout_cornerRadiusTopLeftChecked, 125 | R.styleable.ColorFrameLayout_cornerRadiusTopLeftUnable, 126 | 127 | R.styleable.ColorFrameLayout_cornerRadiusTopRightNormal, 128 | R.styleable.ColorFrameLayout_cornerRadiusTopRightPressed, 129 | R.styleable.ColorFrameLayout_cornerRadiusTopRightSelected, 130 | R.styleable.ColorFrameLayout_cornerRadiusTopRightChecked, 131 | R.styleable.ColorFrameLayout_cornerRadiusTopRightUnable, 132 | 133 | R.styleable.ColorFrameLayout_cornerRadiusBottomLeftNormal, 134 | R.styleable.ColorFrameLayout_cornerRadiusBottomLeftPressed, 135 | R.styleable.ColorFrameLayout_cornerRadiusBottomLeftSelected, 136 | R.styleable.ColorFrameLayout_cornerRadiusBottomLeftChecked, 137 | R.styleable.ColorFrameLayout_cornerRadiusBottomLeftUnable, 138 | 139 | R.styleable.ColorFrameLayout_cornerRadiusBottomRightNormal, 140 | R.styleable.ColorFrameLayout_cornerRadiusBottomRightPressed, 141 | R.styleable.ColorFrameLayout_cornerRadiusBottomRightSelected, 142 | R.styleable.ColorFrameLayout_cornerRadiusBottomRightChecked, 143 | R.styleable.ColorFrameLayout_cornerRadiusBottomRightUnable, 144 | 145 | R.styleable.ColorFrameLayout_borderWidthNormal, 146 | R.styleable.ColorFrameLayout_borderWidthPressed, 147 | R.styleable.ColorFrameLayout_borderWidthSelected, 148 | R.styleable.ColorFrameLayout_borderWidthChecked, 149 | R.styleable.ColorFrameLayout_borderWidthUnable, 150 | 151 | R.styleable.ColorFrameLayout_borderDashWidthNormal, 152 | R.styleable.ColorFrameLayout_borderDashWidthPressed, 153 | R.styleable.ColorFrameLayout_borderDashWidthSelected, 154 | R.styleable.ColorFrameLayout_borderDashWidthChecked, 155 | R.styleable.ColorFrameLayout_borderDashWidthUnable, 156 | 157 | R.styleable.ColorFrameLayout_borderDashGapNormal, 158 | R.styleable.ColorFrameLayout_borderDashGapPressed, 159 | R.styleable.ColorFrameLayout_borderDashGapSelected, 160 | R.styleable.ColorFrameLayout_borderDashGapChecked, 161 | R.styleable.ColorFrameLayout_borderDashGapUnable, 162 | 163 | R.styleable.ColorFrameLayout_borderColorNormal, 164 | R.styleable.ColorFrameLayout_borderColorPressed, 165 | R.styleable.ColorFrameLayout_borderColorSelected, 166 | R.styleable.ColorFrameLayout_borderColorChecked, 167 | R.styleable.ColorFrameLayout_borderColorUnable, 168 | 169 | R.styleable.ColorFrameLayout_backgroundTintPressed); 170 | 171 | typedArray.recycle(); 172 | } 173 | 174 | public ColorViewHelper getColorHelper() { 175 | return mColorViewHelper; 176 | } 177 | 178 | @Deprecated 179 | @Override 180 | public void setBackground(Drawable background) { 181 | super.setBackground(background); 182 | } 183 | 184 | @Deprecated 185 | @Override 186 | public void setBackgroundColor(@ColorInt int color) { 187 | super.setBackgroundColor(color); 188 | } 189 | 190 | @Deprecated 191 | @Override 192 | public void setBackgroundResource(@DrawableRes int resId) { 193 | super.setBackgroundResource(resId); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorImageView.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.util.AttributeSet; 7 | 8 | import androidx.annotation.ColorInt; 9 | import androidx.annotation.DrawableRes; 10 | import androidx.annotation.Nullable; 11 | import androidx.appcompat.widget.AppCompatImageView; 12 | 13 | import com.wei.android.lib.colorview.R; 14 | import com.wei.android.lib.colorview.helper.ColorImageViewHelper; 15 | 16 | 17 | /** 18 | * Created by UCCMAWEI on 2017/11/17. 19 | */ 20 | 21 | public class ColorImageView extends AppCompatImageView { 22 | 23 | private ColorImageViewHelper mColorImageViewHelper; 24 | 25 | public ColorImageView(Context context) { 26 | super(context); 27 | init(null); 28 | } 29 | 30 | public ColorImageView(Context context, AttributeSet attrs) { 31 | super(context, attrs); 32 | init(attrs); 33 | } 34 | 35 | public ColorImageView(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | init(attrs); 38 | } 39 | 40 | private void init(AttributeSet attrs) { 41 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorImageView); 42 | 43 | mColorImageViewHelper = new ColorImageViewHelper(this, 44 | typedArray, 45 | 46 | R.styleable.ColorImageView_srcNormal, 47 | R.styleable.ColorImageView_srcPressed, 48 | R.styleable.ColorImageView_srcSelected, 49 | R.styleable.ColorImageView_srcChecked, 50 | R.styleable.ColorImageView_srcUnable, 51 | 52 | R.styleable.ColorImageView_backgroundColorNormal, 53 | R.styleable.ColorImageView_backgroundColorPressed, 54 | R.styleable.ColorImageView_backgroundColorSelected, 55 | R.styleable.ColorImageView_backgroundColorChecked, 56 | R.styleable.ColorImageView_backgroundColorUnable, 57 | 58 | R.styleable.ColorImageView_backgroundDrawableNormal, 59 | R.styleable.ColorImageView_backgroundDrawablePressed, 60 | R.styleable.ColorImageView_backgroundDrawableSelected, 61 | R.styleable.ColorImageView_backgroundDrawableChecked, 62 | R.styleable.ColorImageView_backgroundDrawableUnable, 63 | 64 | R.styleable.ColorImageView_gradientOrientationNormal, 65 | R.styleable.ColorImageView_gradientOrientationPressed, 66 | R.styleable.ColorImageView_gradientOrientationSelected, 67 | R.styleable.ColorImageView_gradientOrientationChecked, 68 | R.styleable.ColorImageView_gradientOrientationUnable, 69 | 70 | R.styleable.ColorImageView_gradientCenterXNormal, 71 | R.styleable.ColorImageView_gradientCenterXPressed, 72 | R.styleable.ColorImageView_gradientCenterXSelected, 73 | R.styleable.ColorImageView_gradientCenterXChecked, 74 | R.styleable.ColorImageView_gradientCenterXUnable, 75 | 76 | R.styleable.ColorImageView_gradientCenterYNormal, 77 | R.styleable.ColorImageView_gradientCenterYPressed, 78 | R.styleable.ColorImageView_gradientCenterYSelected, 79 | R.styleable.ColorImageView_gradientCenterYChecked, 80 | R.styleable.ColorImageView_gradientCenterYUnable, 81 | 82 | R.styleable.ColorImageView_gradientStartColorNormal, 83 | R.styleable.ColorImageView_gradientStartColorPressed, 84 | R.styleable.ColorImageView_gradientStartColorSelected, 85 | R.styleable.ColorImageView_gradientStartColorChecked, 86 | R.styleable.ColorImageView_gradientStartColorUnable, 87 | 88 | R.styleable.ColorImageView_gradientCenterColorNormal, 89 | R.styleable.ColorImageView_gradientCenterColorPressed, 90 | R.styleable.ColorImageView_gradientCenterColorSelected, 91 | R.styleable.ColorImageView_gradientCenterColorChecked, 92 | R.styleable.ColorImageView_gradientCenterColorUnable, 93 | 94 | R.styleable.ColorImageView_gradientEndColorNormal, 95 | R.styleable.ColorImageView_gradientEndColorPressed, 96 | R.styleable.ColorImageView_gradientEndColorSelected, 97 | R.styleable.ColorImageView_gradientEndColorChecked, 98 | R.styleable.ColorImageView_gradientEndColorUnable, 99 | 100 | R.styleable.ColorImageView_gradientRadiusNormal, 101 | R.styleable.ColorImageView_gradientRadiusPressed, 102 | R.styleable.ColorImageView_gradientRadiusSelected, 103 | R.styleable.ColorImageView_gradientRadiusChecked, 104 | R.styleable.ColorImageView_gradientRadiusUnable, 105 | 106 | R.styleable.ColorImageView_gradientTypeNormal, 107 | R.styleable.ColorImageView_gradientTypePressed, 108 | R.styleable.ColorImageView_gradientTypeSelected, 109 | R.styleable.ColorImageView_gradientTypeChecked, 110 | R.styleable.ColorImageView_gradientTypeUnable, 111 | 112 | R.styleable.ColorImageView_cornerRadiusNormal, 113 | R.styleable.ColorImageView_cornerRadiusPressed, 114 | R.styleable.ColorImageView_cornerRadiusSelected, 115 | R.styleable.ColorImageView_cornerRadiusChecked, 116 | R.styleable.ColorImageView_cornerRadiusUnable, 117 | 118 | R.styleable.ColorImageView_cornerRadiusTopLeftNormal, 119 | R.styleable.ColorImageView_cornerRadiusTopLeftPressed, 120 | R.styleable.ColorImageView_cornerRadiusTopLeftSelected, 121 | R.styleable.ColorImageView_cornerRadiusTopLeftChecked, 122 | R.styleable.ColorImageView_cornerRadiusTopLeftUnable, 123 | 124 | R.styleable.ColorImageView_cornerRadiusTopRightNormal, 125 | R.styleable.ColorImageView_cornerRadiusTopRightPressed, 126 | R.styleable.ColorImageView_cornerRadiusTopRightSelected, 127 | R.styleable.ColorImageView_cornerRadiusTopRightChecked, 128 | R.styleable.ColorImageView_cornerRadiusTopRightUnable, 129 | 130 | R.styleable.ColorImageView_cornerRadiusBottomLeftNormal, 131 | R.styleable.ColorImageView_cornerRadiusBottomLeftPressed, 132 | R.styleable.ColorImageView_cornerRadiusBottomLeftSelected, 133 | R.styleable.ColorImageView_cornerRadiusBottomLeftChecked, 134 | R.styleable.ColorImageView_cornerRadiusBottomLeftUnable, 135 | 136 | R.styleable.ColorImageView_cornerRadiusBottomRightNormal, 137 | R.styleable.ColorImageView_cornerRadiusBottomRightPressed, 138 | R.styleable.ColorImageView_cornerRadiusBottomRightSelected, 139 | R.styleable.ColorImageView_cornerRadiusBottomRightChecked, 140 | R.styleable.ColorImageView_cornerRadiusBottomRightUnable, 141 | 142 | R.styleable.ColorImageView_borderWidthNormal, 143 | R.styleable.ColorImageView_borderWidthPressed, 144 | R.styleable.ColorImageView_borderWidthSelected, 145 | R.styleable.ColorImageView_borderWidthChecked, 146 | R.styleable.ColorImageView_borderWidthUnable, 147 | 148 | R.styleable.ColorImageView_borderDashWidthNormal, 149 | R.styleable.ColorImageView_borderDashWidthPressed, 150 | R.styleable.ColorImageView_borderDashWidthSelected, 151 | R.styleable.ColorImageView_borderDashWidthChecked, 152 | R.styleable.ColorImageView_borderDashWidthUnable, 153 | 154 | R.styleable.ColorImageView_borderDashGapNormal, 155 | R.styleable.ColorImageView_borderDashGapPressed, 156 | R.styleable.ColorImageView_borderDashGapSelected, 157 | R.styleable.ColorImageView_borderDashGapChecked, 158 | R.styleable.ColorImageView_borderDashGapUnable, 159 | 160 | R.styleable.ColorImageView_borderColorNormal, 161 | R.styleable.ColorImageView_borderColorPressed, 162 | R.styleable.ColorImageView_borderColorSelected, 163 | R.styleable.ColorImageView_borderColorChecked, 164 | R.styleable.ColorImageView_borderColorUnable, 165 | 166 | R.styleable.ColorImageView_backgroundTintPressed); 167 | 168 | typedArray.recycle(); 169 | } 170 | 171 | public ColorImageViewHelper getColorHelper() { 172 | return mColorImageViewHelper; 173 | } 174 | 175 | @Deprecated 176 | @Override 177 | public void setBackground(Drawable background) { 178 | super.setBackground(background); 179 | } 180 | 181 | @Deprecated 182 | @Override 183 | public void setBackgroundColor(@ColorInt int color) { 184 | super.setBackgroundColor(color); 185 | } 186 | 187 | @Deprecated 188 | @Override 189 | public void setBackgroundResource(@DrawableRes int resId) { 190 | super.setBackgroundResource(resId); 191 | } 192 | 193 | @Deprecated 194 | @Override 195 | public void setImageDrawable(@Nullable Drawable drawable) { 196 | super.setImageDrawable(drawable); 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.widget.LinearLayout; 10 | 11 | import androidx.annotation.ColorInt; 12 | import androidx.annotation.DrawableRes; 13 | import androidx.annotation.Nullable; 14 | import androidx.annotation.RequiresApi; 15 | 16 | import com.wei.android.lib.colorview.R; 17 | import com.wei.android.lib.colorview.helper.ColorViewHelper; 18 | 19 | 20 | /** 21 | * Created by UCCMAWEI on 2017/11/17. 22 | */ 23 | 24 | public class ColorLinearLayout extends LinearLayout { 25 | 26 | private ColorViewHelper mColorViewHelper; 27 | 28 | public ColorLinearLayout(Context context) { 29 | super(context); 30 | init(null); 31 | } 32 | 33 | public ColorLinearLayout(Context context, @Nullable AttributeSet attrs) { 34 | super(context, attrs); 35 | init(attrs); 36 | } 37 | 38 | public ColorLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 39 | super(context, attrs, defStyleAttr); 40 | init(attrs); 41 | } 42 | 43 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 44 | public ColorLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 45 | super(context, attrs, defStyleAttr, defStyleRes); 46 | init(attrs); 47 | } 48 | 49 | private void init(AttributeSet attrs) { 50 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorLinearLayout); 51 | 52 | mColorViewHelper = new ColorViewHelper(this, 53 | typedArray, 54 | 55 | R.styleable.ColorLinearLayout_backgroundColorNormal, 56 | R.styleable.ColorLinearLayout_backgroundColorPressed, 57 | R.styleable.ColorLinearLayout_backgroundColorSelected, 58 | R.styleable.ColorLinearLayout_backgroundColorChecked, 59 | R.styleable.ColorLinearLayout_backgroundColorUnable, 60 | 61 | R.styleable.ColorLinearLayout_backgroundDrawableNormal, 62 | R.styleable.ColorLinearLayout_backgroundDrawablePressed, 63 | R.styleable.ColorLinearLayout_backgroundDrawableSelected, 64 | R.styleable.ColorLinearLayout_backgroundDrawableChecked, 65 | R.styleable.ColorLinearLayout_backgroundDrawableUnable, 66 | 67 | R.styleable.ColorLinearLayout_gradientOrientationNormal, 68 | R.styleable.ColorLinearLayout_gradientOrientationPressed, 69 | R.styleable.ColorLinearLayout_gradientOrientationSelected, 70 | R.styleable.ColorLinearLayout_gradientOrientationChecked, 71 | R.styleable.ColorLinearLayout_gradientOrientationUnable, 72 | 73 | R.styleable.ColorLinearLayout_gradientCenterXNormal, 74 | R.styleable.ColorLinearLayout_gradientCenterXPressed, 75 | R.styleable.ColorLinearLayout_gradientCenterXSelected, 76 | R.styleable.ColorLinearLayout_gradientCenterXChecked, 77 | R.styleable.ColorLinearLayout_gradientCenterXUnable, 78 | 79 | R.styleable.ColorLinearLayout_gradientCenterYNormal, 80 | R.styleable.ColorLinearLayout_gradientCenterYPressed, 81 | R.styleable.ColorLinearLayout_gradientCenterYSelected, 82 | R.styleable.ColorLinearLayout_gradientCenterYChecked, 83 | R.styleable.ColorLinearLayout_gradientCenterYUnable, 84 | 85 | R.styleable.ColorLinearLayout_gradientStartColorNormal, 86 | R.styleable.ColorLinearLayout_gradientStartColorPressed, 87 | R.styleable.ColorLinearLayout_gradientStartColorSelected, 88 | R.styleable.ColorLinearLayout_gradientStartColorChecked, 89 | R.styleable.ColorLinearLayout_gradientStartColorUnable, 90 | 91 | R.styleable.ColorLinearLayout_gradientCenterColorNormal, 92 | R.styleable.ColorLinearLayout_gradientCenterColorPressed, 93 | R.styleable.ColorLinearLayout_gradientCenterColorSelected, 94 | R.styleable.ColorLinearLayout_gradientCenterColorChecked, 95 | R.styleable.ColorLinearLayout_gradientCenterColorUnable, 96 | 97 | R.styleable.ColorLinearLayout_gradientEndColorNormal, 98 | R.styleable.ColorLinearLayout_gradientEndColorPressed, 99 | R.styleable.ColorLinearLayout_gradientEndColorSelected, 100 | R.styleable.ColorLinearLayout_gradientEndColorChecked, 101 | R.styleable.ColorLinearLayout_gradientEndColorUnable, 102 | 103 | R.styleable.ColorLinearLayout_gradientRadiusNormal, 104 | R.styleable.ColorLinearLayout_gradientRadiusPressed, 105 | R.styleable.ColorLinearLayout_gradientRadiusSelected, 106 | R.styleable.ColorLinearLayout_gradientRadiusChecked, 107 | R.styleable.ColorLinearLayout_gradientRadiusUnable, 108 | 109 | R.styleable.ColorLinearLayout_gradientTypeNormal, 110 | R.styleable.ColorLinearLayout_gradientTypePressed, 111 | R.styleable.ColorLinearLayout_gradientTypeSelected, 112 | R.styleable.ColorLinearLayout_gradientTypeChecked, 113 | R.styleable.ColorLinearLayout_gradientTypeUnable, 114 | 115 | R.styleable.ColorLinearLayout_cornerRadiusNormal, 116 | R.styleable.ColorLinearLayout_cornerRadiusPressed, 117 | R.styleable.ColorLinearLayout_cornerRadiusSelected, 118 | R.styleable.ColorLinearLayout_cornerRadiusChecked, 119 | R.styleable.ColorLinearLayout_cornerRadiusUnable, 120 | 121 | R.styleable.ColorLinearLayout_cornerRadiusTopLeftNormal, 122 | R.styleable.ColorLinearLayout_cornerRadiusTopLeftPressed, 123 | R.styleable.ColorLinearLayout_cornerRadiusTopLeftSelected, 124 | R.styleable.ColorLinearLayout_cornerRadiusTopLeftChecked, 125 | R.styleable.ColorLinearLayout_cornerRadiusTopLeftUnable, 126 | 127 | R.styleable.ColorLinearLayout_cornerRadiusTopRightNormal, 128 | R.styleable.ColorLinearLayout_cornerRadiusTopRightPressed, 129 | R.styleable.ColorLinearLayout_cornerRadiusTopRightSelected, 130 | R.styleable.ColorLinearLayout_cornerRadiusTopRightChecked, 131 | R.styleable.ColorLinearLayout_cornerRadiusTopRightUnable, 132 | 133 | R.styleable.ColorLinearLayout_cornerRadiusBottomLeftNormal, 134 | R.styleable.ColorLinearLayout_cornerRadiusBottomLeftPressed, 135 | R.styleable.ColorLinearLayout_cornerRadiusBottomLeftSelected, 136 | R.styleable.ColorLinearLayout_cornerRadiusBottomLeftChecked, 137 | R.styleable.ColorLinearLayout_cornerRadiusBottomLeftUnable, 138 | 139 | R.styleable.ColorLinearLayout_cornerRadiusBottomRightNormal, 140 | R.styleable.ColorLinearLayout_cornerRadiusBottomRightPressed, 141 | R.styleable.ColorLinearLayout_cornerRadiusBottomRightSelected, 142 | R.styleable.ColorLinearLayout_cornerRadiusBottomRightChecked, 143 | R.styleable.ColorLinearLayout_cornerRadiusBottomRightUnable, 144 | 145 | R.styleable.ColorLinearLayout_borderWidthNormal, 146 | R.styleable.ColorLinearLayout_borderWidthPressed, 147 | R.styleable.ColorLinearLayout_borderWidthSelected, 148 | R.styleable.ColorLinearLayout_borderWidthChecked, 149 | R.styleable.ColorLinearLayout_borderWidthUnable, 150 | 151 | R.styleable.ColorLinearLayout_borderDashWidthNormal, 152 | R.styleable.ColorLinearLayout_borderDashWidthPressed, 153 | R.styleable.ColorLinearLayout_borderDashWidthSelected, 154 | R.styleable.ColorLinearLayout_borderDashWidthChecked, 155 | R.styleable.ColorLinearLayout_borderDashWidthUnable, 156 | 157 | R.styleable.ColorLinearLayout_borderDashGapNormal, 158 | R.styleable.ColorLinearLayout_borderDashGapPressed, 159 | R.styleable.ColorLinearLayout_borderDashGapSelected, 160 | R.styleable.ColorLinearLayout_borderDashGapChecked, 161 | R.styleable.ColorLinearLayout_borderDashGapUnable, 162 | 163 | R.styleable.ColorLinearLayout_borderColorNormal, 164 | R.styleable.ColorLinearLayout_borderColorPressed, 165 | R.styleable.ColorLinearLayout_borderColorSelected, 166 | R.styleable.ColorLinearLayout_borderColorChecked, 167 | R.styleable.ColorLinearLayout_borderColorUnable, 168 | 169 | R.styleable.ColorLinearLayout_backgroundTintPressed); 170 | 171 | typedArray.recycle(); 172 | } 173 | 174 | public ColorViewHelper getColorHelper() { 175 | return mColorViewHelper; 176 | } 177 | 178 | @Deprecated 179 | @Override 180 | public void setBackground(Drawable background) { 181 | super.setBackground(background); 182 | } 183 | 184 | @Deprecated 185 | @Override 186 | public void setBackgroundColor(@ColorInt int color) { 187 | super.setBackgroundColor(color); 188 | } 189 | 190 | @Deprecated 191 | @Override 192 | public void setBackgroundResource(@DrawableRes int resId) { 193 | super.setBackgroundResource(resId); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorRelativeLayout.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.widget.RelativeLayout; 10 | 11 | import androidx.annotation.ColorInt; 12 | import androidx.annotation.DrawableRes; 13 | import androidx.annotation.Nullable; 14 | import androidx.annotation.RequiresApi; 15 | 16 | import com.wei.android.lib.colorview.R; 17 | import com.wei.android.lib.colorview.helper.ColorViewHelper; 18 | 19 | /** 20 | * Created by UCCMAWEI on 2017/11/17. 21 | */ 22 | 23 | public class ColorRelativeLayout extends RelativeLayout { 24 | 25 | private ColorViewHelper mColorViewHelper; 26 | 27 | public ColorRelativeLayout(Context context) { 28 | super(context); 29 | init(null); 30 | } 31 | 32 | public ColorRelativeLayout(Context context, @Nullable AttributeSet attrs) { 33 | super(context, attrs); 34 | init(attrs); 35 | } 36 | 37 | public ColorRelativeLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 38 | super(context, attrs, defStyleAttr); 39 | init(attrs); 40 | } 41 | 42 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 43 | public ColorRelativeLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 44 | super(context, attrs, defStyleAttr, defStyleRes); 45 | init(attrs); 46 | } 47 | 48 | private void init(AttributeSet attrs) { 49 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorRelativeLayout); 50 | 51 | mColorViewHelper = new ColorViewHelper(this, 52 | typedArray, 53 | 54 | R.styleable.ColorRelativeLayout_backgroundColorNormal, 55 | R.styleable.ColorRelativeLayout_backgroundColorPressed, 56 | R.styleable.ColorRelativeLayout_backgroundColorSelected, 57 | R.styleable.ColorRelativeLayout_backgroundColorChecked, 58 | R.styleable.ColorRelativeLayout_backgroundColorUnable, 59 | 60 | R.styleable.ColorRelativeLayout_backgroundDrawableNormal, 61 | R.styleable.ColorRelativeLayout_backgroundDrawablePressed, 62 | R.styleable.ColorRelativeLayout_backgroundDrawableSelected, 63 | R.styleable.ColorRelativeLayout_backgroundDrawableChecked, 64 | R.styleable.ColorRelativeLayout_backgroundDrawableUnable, 65 | 66 | R.styleable.ColorRelativeLayout_gradientOrientationNormal, 67 | R.styleable.ColorRelativeLayout_gradientOrientationPressed, 68 | R.styleable.ColorRelativeLayout_gradientOrientationSelected, 69 | R.styleable.ColorRelativeLayout_gradientOrientationChecked, 70 | R.styleable.ColorRelativeLayout_gradientOrientationUnable, 71 | 72 | R.styleable.ColorRelativeLayout_gradientCenterXNormal, 73 | R.styleable.ColorRelativeLayout_gradientCenterXPressed, 74 | R.styleable.ColorRelativeLayout_gradientCenterXSelected, 75 | R.styleable.ColorRelativeLayout_gradientCenterXChecked, 76 | R.styleable.ColorRelativeLayout_gradientCenterXUnable, 77 | 78 | R.styleable.ColorRelativeLayout_gradientCenterYNormal, 79 | R.styleable.ColorRelativeLayout_gradientCenterYPressed, 80 | R.styleable.ColorRelativeLayout_gradientCenterYSelected, 81 | R.styleable.ColorRelativeLayout_gradientCenterYChecked, 82 | R.styleable.ColorRelativeLayout_gradientCenterYUnable, 83 | 84 | R.styleable.ColorRelativeLayout_gradientStartColorNormal, 85 | R.styleable.ColorRelativeLayout_gradientStartColorPressed, 86 | R.styleable.ColorRelativeLayout_gradientStartColorSelected, 87 | R.styleable.ColorRelativeLayout_gradientStartColorChecked, 88 | R.styleable.ColorRelativeLayout_gradientStartColorUnable, 89 | 90 | R.styleable.ColorRelativeLayout_gradientCenterColorNormal, 91 | R.styleable.ColorRelativeLayout_gradientCenterColorPressed, 92 | R.styleable.ColorRelativeLayout_gradientCenterColorSelected, 93 | R.styleable.ColorRelativeLayout_gradientCenterColorChecked, 94 | R.styleable.ColorRelativeLayout_gradientCenterColorUnable, 95 | 96 | R.styleable.ColorRelativeLayout_gradientEndColorNormal, 97 | R.styleable.ColorRelativeLayout_gradientEndColorPressed, 98 | R.styleable.ColorRelativeLayout_gradientEndColorSelected, 99 | R.styleable.ColorRelativeLayout_gradientEndColorChecked, 100 | R.styleable.ColorRelativeLayout_gradientEndColorUnable, 101 | 102 | R.styleable.ColorRelativeLayout_gradientRadiusNormal, 103 | R.styleable.ColorRelativeLayout_gradientRadiusPressed, 104 | R.styleable.ColorRelativeLayout_gradientRadiusSelected, 105 | R.styleable.ColorRelativeLayout_gradientRadiusChecked, 106 | R.styleable.ColorRelativeLayout_gradientRadiusUnable, 107 | 108 | R.styleable.ColorRelativeLayout_gradientTypeNormal, 109 | R.styleable.ColorRelativeLayout_gradientTypePressed, 110 | R.styleable.ColorRelativeLayout_gradientTypeSelected, 111 | R.styleable.ColorRelativeLayout_gradientTypeChecked, 112 | R.styleable.ColorRelativeLayout_gradientTypeUnable, 113 | 114 | R.styleable.ColorRelativeLayout_cornerRadiusNormal, 115 | R.styleable.ColorRelativeLayout_cornerRadiusPressed, 116 | R.styleable.ColorRelativeLayout_cornerRadiusSelected, 117 | R.styleable.ColorRelativeLayout_cornerRadiusChecked, 118 | R.styleable.ColorRelativeLayout_cornerRadiusUnable, 119 | 120 | R.styleable.ColorRelativeLayout_cornerRadiusTopLeftNormal, 121 | R.styleable.ColorRelativeLayout_cornerRadiusTopLeftPressed, 122 | R.styleable.ColorRelativeLayout_cornerRadiusTopLeftSelected, 123 | R.styleable.ColorRelativeLayout_cornerRadiusTopLeftChecked, 124 | R.styleable.ColorRelativeLayout_cornerRadiusTopLeftUnable, 125 | 126 | R.styleable.ColorRelativeLayout_cornerRadiusTopRightNormal, 127 | R.styleable.ColorRelativeLayout_cornerRadiusTopRightPressed, 128 | R.styleable.ColorRelativeLayout_cornerRadiusTopRightSelected, 129 | R.styleable.ColorRelativeLayout_cornerRadiusTopRightChecked, 130 | R.styleable.ColorRelativeLayout_cornerRadiusTopRightUnable, 131 | 132 | R.styleable.ColorRelativeLayout_cornerRadiusBottomLeftNormal, 133 | R.styleable.ColorRelativeLayout_cornerRadiusBottomLeftPressed, 134 | R.styleable.ColorRelativeLayout_cornerRadiusBottomLeftSelected, 135 | R.styleable.ColorRelativeLayout_cornerRadiusBottomLeftChecked, 136 | R.styleable.ColorRelativeLayout_cornerRadiusBottomLeftUnable, 137 | 138 | R.styleable.ColorRelativeLayout_cornerRadiusBottomRightNormal, 139 | R.styleable.ColorRelativeLayout_cornerRadiusBottomRightPressed, 140 | R.styleable.ColorRelativeLayout_cornerRadiusBottomRightSelected, 141 | R.styleable.ColorRelativeLayout_cornerRadiusBottomRightChecked, 142 | R.styleable.ColorRelativeLayout_cornerRadiusBottomRightUnable, 143 | 144 | R.styleable.ColorRelativeLayout_borderWidthNormal, 145 | R.styleable.ColorRelativeLayout_borderWidthPressed, 146 | R.styleable.ColorRelativeLayout_borderWidthSelected, 147 | R.styleable.ColorRelativeLayout_borderWidthChecked, 148 | R.styleable.ColorRelativeLayout_borderWidthUnable, 149 | 150 | R.styleable.ColorRelativeLayout_borderDashWidthNormal, 151 | R.styleable.ColorRelativeLayout_borderDashWidthPressed, 152 | R.styleable.ColorRelativeLayout_borderDashWidthSelected, 153 | R.styleable.ColorRelativeLayout_borderDashWidthChecked, 154 | R.styleable.ColorRelativeLayout_borderDashWidthUnable, 155 | 156 | R.styleable.ColorRelativeLayout_borderDashGapNormal, 157 | R.styleable.ColorRelativeLayout_borderDashGapPressed, 158 | R.styleable.ColorRelativeLayout_borderDashGapSelected, 159 | R.styleable.ColorRelativeLayout_borderDashGapChecked, 160 | R.styleable.ColorRelativeLayout_borderDashGapUnable, 161 | 162 | R.styleable.ColorRelativeLayout_borderColorNormal, 163 | R.styleable.ColorRelativeLayout_borderColorPressed, 164 | R.styleable.ColorRelativeLayout_borderColorSelected, 165 | R.styleable.ColorRelativeLayout_borderColorChecked, 166 | R.styleable.ColorRelativeLayout_borderColorUnable, 167 | 168 | R.styleable.ColorRelativeLayout_backgroundTintPressed); 169 | 170 | typedArray.recycle(); 171 | } 172 | 173 | public ColorViewHelper getColorHelper() { 174 | return mColorViewHelper; 175 | } 176 | 177 | @Deprecated 178 | @Override 179 | public void setBackground(Drawable background) { 180 | super.setBackground(background); 181 | } 182 | 183 | @Deprecated 184 | @Override 185 | public void setBackgroundColor(@ColorInt int color) { 186 | super.setBackgroundColor(color); 187 | } 188 | 189 | @Deprecated 190 | @Override 191 | public void setBackgroundResource(@DrawableRes int resId) { 192 | super.setBackgroundResource(resId); 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorTextView.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.ColorStateList; 5 | import android.content.res.TypedArray; 6 | import android.graphics.drawable.Drawable; 7 | import android.util.AttributeSet; 8 | 9 | import androidx.annotation.ColorInt; 10 | import androidx.annotation.DrawableRes; 11 | import androidx.appcompat.widget.AppCompatTextView; 12 | 13 | import com.wei.android.lib.colorview.R; 14 | import com.wei.android.lib.colorview.helper.ColorTextViewHelper; 15 | 16 | 17 | /** 18 | * Created by UCCMAWEI on 2017/11/17. 19 | */ 20 | 21 | public class ColorTextView extends AppCompatTextView { 22 | 23 | private ColorTextViewHelper mColorTextViewHelper; 24 | 25 | public ColorTextView(Context context) { 26 | super(context); 27 | init(null); 28 | } 29 | 30 | public ColorTextView(Context context, AttributeSet attrs) { 31 | super(context, attrs); 32 | init(attrs); 33 | } 34 | 35 | public ColorTextView(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | init(attrs); 38 | } 39 | 40 | private void init(AttributeSet attrs) { 41 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorTextView); 42 | 43 | mColorTextViewHelper = new ColorTextViewHelper(this, 44 | typedArray, 45 | 46 | getCurrentTextColor(), 47 | R.styleable.ColorTextView_textColorNormal, 48 | R.styleable.ColorTextView_textColorPressed, 49 | R.styleable.ColorTextView_textColorSelected, 50 | R.styleable.ColorTextView_textColorChecked, 51 | R.styleable.ColorTextView_textColorUnable, 52 | 53 | R.styleable.ColorTextView_textStrokeWidth, 54 | 55 | getCurrentHintTextColor(), 56 | R.styleable.ColorTextView_textColorHintNormal, 57 | R.styleable.ColorTextView_textColorHintPressed, 58 | R.styleable.ColorTextView_textColorHintSelected, 59 | R.styleable.ColorTextView_textColorHintChecked, 60 | R.styleable.ColorTextView_textColorHintUnable, 61 | 62 | R.styleable.ColorTextView_backgroundColorNormal, 63 | R.styleable.ColorTextView_backgroundColorPressed, 64 | R.styleable.ColorTextView_backgroundColorSelected, 65 | R.styleable.ColorTextView_backgroundColorChecked, 66 | R.styleable.ColorTextView_backgroundColorUnable, 67 | 68 | R.styleable.ColorTextView_backgroundDrawableNormal, 69 | R.styleable.ColorTextView_backgroundDrawablePressed, 70 | R.styleable.ColorTextView_backgroundDrawableSelected, 71 | R.styleable.ColorTextView_backgroundDrawableChecked, 72 | R.styleable.ColorTextView_backgroundDrawableUnable, 73 | 74 | R.styleable.ColorTextView_gradientOrientationNormal, 75 | R.styleable.ColorTextView_gradientOrientationPressed, 76 | R.styleable.ColorTextView_gradientOrientationSelected, 77 | R.styleable.ColorTextView_gradientOrientationChecked, 78 | R.styleable.ColorTextView_gradientOrientationUnable, 79 | 80 | R.styleable.ColorTextView_gradientCenterXNormal, 81 | R.styleable.ColorTextView_gradientCenterXPressed, 82 | R.styleable.ColorTextView_gradientCenterXSelected, 83 | R.styleable.ColorTextView_gradientCenterXChecked, 84 | R.styleable.ColorTextView_gradientCenterXUnable, 85 | 86 | R.styleable.ColorTextView_gradientCenterYNormal, 87 | R.styleable.ColorTextView_gradientCenterYPressed, 88 | R.styleable.ColorTextView_gradientCenterYSelected, 89 | R.styleable.ColorTextView_gradientCenterYChecked, 90 | R.styleable.ColorTextView_gradientCenterYUnable, 91 | 92 | R.styleable.ColorTextView_gradientStartColorNormal, 93 | R.styleable.ColorTextView_gradientStartColorPressed, 94 | R.styleable.ColorTextView_gradientStartColorSelected, 95 | R.styleable.ColorTextView_gradientStartColorChecked, 96 | R.styleable.ColorTextView_gradientStartColorUnable, 97 | 98 | R.styleable.ColorTextView_gradientCenterColorNormal, 99 | R.styleable.ColorTextView_gradientCenterColorPressed, 100 | R.styleable.ColorTextView_gradientCenterColorSelected, 101 | R.styleable.ColorTextView_gradientCenterColorChecked, 102 | R.styleable.ColorTextView_gradientCenterColorUnable, 103 | 104 | R.styleable.ColorTextView_gradientEndColorNormal, 105 | R.styleable.ColorTextView_gradientEndColorPressed, 106 | R.styleable.ColorTextView_gradientEndColorSelected, 107 | R.styleable.ColorTextView_gradientEndColorChecked, 108 | R.styleable.ColorTextView_gradientEndColorUnable, 109 | 110 | R.styleable.ColorTextView_gradientRadiusNormal, 111 | R.styleable.ColorTextView_gradientRadiusPressed, 112 | R.styleable.ColorTextView_gradientRadiusSelected, 113 | R.styleable.ColorTextView_gradientRadiusChecked, 114 | R.styleable.ColorTextView_gradientRadiusUnable, 115 | 116 | R.styleable.ColorTextView_gradientTypeNormal, 117 | R.styleable.ColorTextView_gradientTypePressed, 118 | R.styleable.ColorTextView_gradientTypeSelected, 119 | R.styleable.ColorTextView_gradientTypeChecked, 120 | R.styleable.ColorTextView_gradientTypeUnable, 121 | 122 | R.styleable.ColorTextView_cornerRadiusNormal, 123 | R.styleable.ColorTextView_cornerRadiusPressed, 124 | R.styleable.ColorTextView_cornerRadiusSelected, 125 | R.styleable.ColorTextView_cornerRadiusChecked, 126 | R.styleable.ColorTextView_cornerRadiusUnable, 127 | 128 | R.styleable.ColorTextView_cornerRadiusTopLeftNormal, 129 | R.styleable.ColorTextView_cornerRadiusTopLeftPressed, 130 | R.styleable.ColorTextView_cornerRadiusTopLeftSelected, 131 | R.styleable.ColorTextView_cornerRadiusTopLeftChecked, 132 | R.styleable.ColorTextView_cornerRadiusTopLeftUnable, 133 | 134 | R.styleable.ColorTextView_cornerRadiusTopRightNormal, 135 | R.styleable.ColorTextView_cornerRadiusTopRightPressed, 136 | R.styleable.ColorTextView_cornerRadiusTopRightSelected, 137 | R.styleable.ColorTextView_cornerRadiusTopRightChecked, 138 | R.styleable.ColorTextView_cornerRadiusTopRightUnable, 139 | 140 | R.styleable.ColorTextView_cornerRadiusBottomLeftNormal, 141 | R.styleable.ColorTextView_cornerRadiusBottomLeftPressed, 142 | R.styleable.ColorTextView_cornerRadiusBottomLeftSelected, 143 | R.styleable.ColorTextView_cornerRadiusBottomLeftChecked, 144 | R.styleable.ColorTextView_cornerRadiusBottomLeftUnable, 145 | 146 | R.styleable.ColorTextView_cornerRadiusBottomRightNormal, 147 | R.styleable.ColorTextView_cornerRadiusBottomRightPressed, 148 | R.styleable.ColorTextView_cornerRadiusBottomRightSelected, 149 | R.styleable.ColorTextView_cornerRadiusBottomRightChecked, 150 | R.styleable.ColorTextView_cornerRadiusBottomRightUnable, 151 | 152 | R.styleable.ColorTextView_borderWidthNormal, 153 | R.styleable.ColorTextView_borderWidthPressed, 154 | R.styleable.ColorTextView_borderWidthSelected, 155 | R.styleable.ColorTextView_borderWidthChecked, 156 | R.styleable.ColorTextView_borderWidthUnable, 157 | 158 | R.styleable.ColorTextView_borderDashWidthNormal, 159 | R.styleable.ColorTextView_borderDashWidthPressed, 160 | R.styleable.ColorTextView_borderDashWidthSelected, 161 | R.styleable.ColorTextView_borderDashWidthChecked, 162 | R.styleable.ColorTextView_borderDashWidthUnable, 163 | 164 | R.styleable.ColorTextView_borderDashGapNormal, 165 | R.styleable.ColorTextView_borderDashGapPressed, 166 | R.styleable.ColorTextView_borderDashGapSelected, 167 | R.styleable.ColorTextView_borderDashGapChecked, 168 | R.styleable.ColorTextView_borderDashGapUnable, 169 | 170 | R.styleable.ColorTextView_borderColorNormal, 171 | R.styleable.ColorTextView_borderColorPressed, 172 | R.styleable.ColorTextView_borderColorSelected, 173 | R.styleable.ColorTextView_borderColorChecked, 174 | R.styleable.ColorTextView_borderColorUnable, 175 | 176 | R.styleable.ColorTextView_drawableLeftNormal, 177 | R.styleable.ColorTextView_drawableLeftPressed, 178 | R.styleable.ColorTextView_drawableLeftSelected, 179 | R.styleable.ColorTextView_drawableLeftChecked, 180 | R.styleable.ColorTextView_drawableLeftUnable, 181 | 182 | R.styleable.ColorTextView_drawableTopNormal, 183 | R.styleable.ColorTextView_drawableTopPressed, 184 | R.styleable.ColorTextView_drawableTopSelected, 185 | R.styleable.ColorTextView_drawableTopChecked, 186 | R.styleable.ColorTextView_drawableTopUnable, 187 | 188 | R.styleable.ColorTextView_drawableRightNormal, 189 | R.styleable.ColorTextView_drawableRightPressed, 190 | R.styleable.ColorTextView_drawableRightSelected, 191 | R.styleable.ColorTextView_drawableRightChecked, 192 | R.styleable.ColorTextView_drawableRightUnable, 193 | 194 | R.styleable.ColorTextView_drawableBottomNormal, 195 | R.styleable.ColorTextView_drawableBottomPressed, 196 | R.styleable.ColorTextView_drawableBottomSelected, 197 | R.styleable.ColorTextView_drawableBottomChecked, 198 | R.styleable.ColorTextView_drawableBottomUnable, 199 | 200 | R.styleable.ColorTextView_drawableLeftWidth, 201 | R.styleable.ColorTextView_drawableLeftHeight, 202 | 203 | R.styleable.ColorTextView_drawableTopWidth, 204 | R.styleable.ColorTextView_drawableTopHeight, 205 | 206 | R.styleable.ColorTextView_drawableRightWidth, 207 | R.styleable.ColorTextView_drawableRightHeight, 208 | 209 | R.styleable.ColorTextView_drawableBottomWidth, 210 | R.styleable.ColorTextView_drawableBottomHeight, 211 | 212 | R.styleable.ColorTextView_backgroundTintPressed); 213 | 214 | typedArray.recycle(); 215 | } 216 | 217 | public ColorTextViewHelper getColorHelper() { 218 | return mColorTextViewHelper; 219 | } 220 | 221 | @Deprecated 222 | @Override 223 | public void setBackground(Drawable background) { 224 | super.setBackground(background); 225 | } 226 | 227 | @Deprecated 228 | @Override 229 | public void setBackgroundColor(@ColorInt int color) { 230 | super.setBackgroundColor(color); 231 | } 232 | 233 | @Deprecated 234 | @Override 235 | public void setBackgroundResource(@DrawableRes int resId) { 236 | super.setBackgroundResource(resId); 237 | } 238 | 239 | @Deprecated 240 | @Override 241 | public void setTextColor(@ColorInt int color) { 242 | super.setTextColor(color); 243 | } 244 | 245 | @Deprecated 246 | @Override 247 | public void setTextColor(ColorStateList colors) { 248 | super.setTextColor(colors); 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /ColorViewLib/src/main/java/com/wei/android/lib/colorview/view/ColorView.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | 10 | import androidx.annotation.ColorInt; 11 | import androidx.annotation.DrawableRes; 12 | import androidx.annotation.Nullable; 13 | import androidx.annotation.RequiresApi; 14 | 15 | import com.wei.android.lib.colorview.R; 16 | import com.wei.android.lib.colorview.helper.ColorViewHelper; 17 | 18 | /** 19 | * Created by UCCMAWEI on 2017/11/17. 20 | */ 21 | 22 | public class ColorView extends View { 23 | 24 | private ColorViewHelper mColorViewHelper; 25 | 26 | public ColorView(Context context) { 27 | super(context); 28 | init(null); 29 | } 30 | 31 | public ColorView(Context context, @Nullable AttributeSet attrs) { 32 | super(context, attrs); 33 | init(attrs); 34 | } 35 | 36 | public ColorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 37 | super(context, attrs, defStyleAttr); 38 | init(attrs); 39 | } 40 | 41 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 42 | public ColorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 43 | super(context, attrs, defStyleAttr, defStyleRes); 44 | init(attrs); 45 | } 46 | 47 | private void init(AttributeSet attrs) { 48 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ColorView); 49 | 50 | mColorViewHelper = new ColorViewHelper(this, 51 | typedArray, 52 | 53 | R.styleable.ColorView_backgroundColorNormal, 54 | R.styleable.ColorView_backgroundColorPressed, 55 | R.styleable.ColorView_backgroundColorSelected, 56 | R.styleable.ColorView_backgroundColorChecked, 57 | R.styleable.ColorView_backgroundColorUnable, 58 | 59 | R.styleable.ColorView_backgroundDrawableNormal, 60 | R.styleable.ColorView_backgroundDrawablePressed, 61 | R.styleable.ColorView_backgroundDrawableSelected, 62 | R.styleable.ColorView_backgroundDrawableChecked, 63 | R.styleable.ColorView_backgroundDrawableUnable, 64 | 65 | R.styleable.ColorView_gradientOrientationNormal, 66 | R.styleable.ColorView_gradientOrientationPressed, 67 | R.styleable.ColorView_gradientOrientationSelected, 68 | R.styleable.ColorView_gradientOrientationChecked, 69 | R.styleable.ColorView_gradientOrientationUnable, 70 | 71 | R.styleable.ColorView_gradientCenterXNormal, 72 | R.styleable.ColorView_gradientCenterXPressed, 73 | R.styleable.ColorView_gradientCenterXSelected, 74 | R.styleable.ColorView_gradientCenterXChecked, 75 | R.styleable.ColorView_gradientCenterXUnable, 76 | 77 | R.styleable.ColorView_gradientCenterYNormal, 78 | R.styleable.ColorView_gradientCenterYPressed, 79 | R.styleable.ColorView_gradientCenterYSelected, 80 | R.styleable.ColorView_gradientCenterYChecked, 81 | R.styleable.ColorView_gradientCenterYUnable, 82 | 83 | R.styleable.ColorView_gradientStartColorNormal, 84 | R.styleable.ColorView_gradientStartColorPressed, 85 | R.styleable.ColorView_gradientStartColorSelected, 86 | R.styleable.ColorView_gradientStartColorChecked, 87 | R.styleable.ColorView_gradientStartColorUnable, 88 | 89 | R.styleable.ColorView_gradientCenterColorNormal, 90 | R.styleable.ColorView_gradientCenterColorPressed, 91 | R.styleable.ColorView_gradientCenterColorSelected, 92 | R.styleable.ColorView_gradientCenterColorChecked, 93 | R.styleable.ColorView_gradientCenterColorUnable, 94 | 95 | R.styleable.ColorView_gradientEndColorNormal, 96 | R.styleable.ColorView_gradientEndColorPressed, 97 | R.styleable.ColorView_gradientEndColorSelected, 98 | R.styleable.ColorView_gradientEndColorChecked, 99 | R.styleable.ColorView_gradientEndColorUnable, 100 | 101 | R.styleable.ColorView_gradientRadiusNormal, 102 | R.styleable.ColorView_gradientRadiusPressed, 103 | R.styleable.ColorView_gradientRadiusSelected, 104 | R.styleable.ColorView_gradientRadiusChecked, 105 | R.styleable.ColorView_gradientRadiusUnable, 106 | 107 | R.styleable.ColorView_gradientTypeNormal, 108 | R.styleable.ColorView_gradientTypePressed, 109 | R.styleable.ColorView_gradientTypeSelected, 110 | R.styleable.ColorView_gradientTypeChecked, 111 | R.styleable.ColorView_gradientTypeUnable, 112 | 113 | R.styleable.ColorView_cornerRadiusNormal, 114 | R.styleable.ColorView_cornerRadiusPressed, 115 | R.styleable.ColorView_cornerRadiusSelected, 116 | R.styleable.ColorView_cornerRadiusChecked, 117 | R.styleable.ColorView_cornerRadiusUnable, 118 | 119 | R.styleable.ColorView_cornerRadiusTopLeftNormal, 120 | R.styleable.ColorView_cornerRadiusTopLeftPressed, 121 | R.styleable.ColorView_cornerRadiusTopLeftSelected, 122 | R.styleable.ColorView_cornerRadiusTopLeftChecked, 123 | R.styleable.ColorView_cornerRadiusTopLeftUnable, 124 | 125 | R.styleable.ColorView_cornerRadiusTopRightNormal, 126 | R.styleable.ColorView_cornerRadiusTopRightPressed, 127 | R.styleable.ColorView_cornerRadiusTopRightSelected, 128 | R.styleable.ColorView_cornerRadiusTopRightChecked, 129 | R.styleable.ColorView_cornerRadiusTopRightUnable, 130 | 131 | R.styleable.ColorView_cornerRadiusBottomLeftNormal, 132 | R.styleable.ColorView_cornerRadiusBottomLeftPressed, 133 | R.styleable.ColorView_cornerRadiusBottomLeftSelected, 134 | R.styleable.ColorView_cornerRadiusBottomLeftChecked, 135 | R.styleable.ColorView_cornerRadiusBottomLeftUnable, 136 | 137 | R.styleable.ColorView_cornerRadiusBottomRightNormal, 138 | R.styleable.ColorView_cornerRadiusBottomRightPressed, 139 | R.styleable.ColorView_cornerRadiusBottomRightSelected, 140 | R.styleable.ColorView_cornerRadiusBottomRightChecked, 141 | R.styleable.ColorView_cornerRadiusBottomRightUnable, 142 | 143 | R.styleable.ColorView_borderWidthNormal, 144 | R.styleable.ColorView_borderWidthPressed, 145 | R.styleable.ColorView_borderWidthSelected, 146 | R.styleable.ColorView_borderWidthChecked, 147 | R.styleable.ColorView_borderWidthUnable, 148 | 149 | R.styleable.ColorView_borderDashWidthNormal, 150 | R.styleable.ColorView_borderDashWidthPressed, 151 | R.styleable.ColorView_borderDashWidthSelected, 152 | R.styleable.ColorView_borderDashWidthChecked, 153 | R.styleable.ColorView_borderDashWidthUnable, 154 | 155 | R.styleable.ColorView_borderDashGapNormal, 156 | R.styleable.ColorView_borderDashGapPressed, 157 | R.styleable.ColorView_borderDashGapSelected, 158 | R.styleable.ColorView_borderDashGapChecked, 159 | R.styleable.ColorView_borderDashGapUnable, 160 | 161 | R.styleable.ColorView_borderColorNormal, 162 | R.styleable.ColorView_borderColorPressed, 163 | R.styleable.ColorView_borderColorSelected, 164 | R.styleable.ColorView_borderColorChecked, 165 | R.styleable.ColorView_borderColorUnable, 166 | 167 | R.styleable.ColorView_backgroundTintPressed); 168 | 169 | typedArray.recycle(); 170 | } 171 | 172 | public ColorViewHelper getColorHelper() { 173 | return mColorViewHelper; 174 | } 175 | 176 | @Deprecated 177 | @Override 178 | public void setBackground(Drawable background) { 179 | super.setBackground(background); 180 | } 181 | 182 | @Deprecated 183 | @Override 184 | public void setBackgroundColor(@ColorInt int color) { 185 | super.setBackgroundColor(color); 186 | } 187 | 188 | @Deprecated 189 | @Override 190 | public void setBackgroundResource(@DrawableRes int resId) { 191 | super.setBackgroundResource(resId); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /ColorViewLib/src/test/java/com/wei/android/lib/colorview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.wei.android.lib.colorview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Awei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ColorView 2 | ======== 3 | 4 | 抛弃 Selector 和 Shape ,直接在布局文件中实现多彩样式。 5 | 6 | ![](https://github.com/uccmawei/ColorView/raw/master/demo.png) 7 | 8 | 9 | **1. Gradle 添加引用** 10 | 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | dependencies { 18 | implementation 'com.github.uccmawei:ColorView:1.3.5' 19 | } 20 | 21 | **2. 拓展的View** 22 | 23 | ColorView 24 | ColorButton 25 | ColorTextView 26 | ColorEditText 27 | ColorImageView 28 | ColorFrameLayout 29 | ColorLinearLayout 30 | ColorRelativeLayout 31 | 32 | **3. 拓展的属性** 33 | 34 | 以下带有Normal字样的属性都支持以下五种状态: 35 | Normal,Pressed,Selected,Checked,Unable 36 | 37 | app:backgroundColorNormal="#FFFFFF" // 背景色 38 | app:backgroundDrawableNormal="@drawable/apple" // 背景图 39 | app:gradientOrientationNormal="TL_BR" // 渐变角度:左上到右下 40 | app:gradientCenterXNormal="0.5" // 渐变中心 41 | app:gradientCenterYNormal="0.5" // 渐变中心 42 | app:gradientStartColorNormal="#FFFFFF" // 渐变开始颜色 43 | app:gradientCenterColorNormal="#FFFFFF" // 渐变中间颜色 44 | app:gradientEndColorNormal="#FFFFFF" // 渐变末尾颜色 45 | app:gradientRadiusNormal="20dp" // 渐变辐射半径 46 | app:gradientTypeNormal="linear" // 渐变类型:默认线性 47 | app:textColorNormal="#FFFFFF" // 文字颜色 48 | app:textColorHintNormal="#FFFFFF" // 提示文字颜色 49 | app:srcNormal="@drawable/apple" // 图片资源 50 | app:cornerRadiusNormal="20dp" // 背景圆角 51 | app:cornerRadiusTopLeftNormal="20dp" // 背景圆角,左上 52 | app:cornerRadiusTopRightNormal="20dp" // 背景圆角,右上 53 | app:cornerRadiusBottomLeftNormal="20dp" // 背景圆角,左下 54 | app:cornerRadiusBottomRightNormal="20dp" // 背景圆角,右下 55 | app:borderWidthNormal="2dp" // 边框粗细 56 | app:borderDashGapNormal="20dp" // 边框虚线之间的间隔 57 | app:borderDashWidthNormal="20dp" // 边框虚线大小 58 | app:borderColorNormal="#FFFFFF" // 边框颜色 59 | app:drawableLeftNormal="@drawable/banana" // 左边图标 60 | app:drawableTopNormal="@drawable/banana" // 上边图标 61 | app:drawableRightNormal="@drawable/banana" // 右边图标 62 | app:drawableBottomNormal="@drawable/banana" // 下边图标 63 | app:drawableLeftWidth="20dp" // 左边图标宽度 64 | app:drawableLeftHeight="20dp" // 左边图标高度 65 | app:drawableTopWidth="20dp" // 上边图标宽度 66 | app:drawableTopHeight="20dp" // 上边图标高度 67 | app:drawableRightWidth="20dp" // 右边图标宽度 68 | app:drawableRightHeight="20dp" // 右边图标高度 69 | app:drawableBottomWidth="20dp" // 下边图标宽度 70 | app:drawableBottomHeight="20dp" // 下边图标高度 71 | 72 | app:backgroundTintPressed="#33FF0000" // 点击时背景遮罩层,仅支持5.0及以上系统 73 | app:textStrokeWidth="0.1" // 文字加粗 74 | 75 | **3. 属性介绍** 76 | 77 | 1. Normal属性具有默认性,其他属性的默认值都跟Normal保持一致。 78 | 79 | 2. 背景图片的和背景颜色一起设定时,背景图片会覆盖背景颜色。 80 | 81 | 3. 需要更新某个属性则调用:view.getColorHelper().setXXX(); 82 | 83 | **4. 开发笔记** 84 | 85 | [1. 加粗边框时需要重新构建背景对象,否则背景边框绘制不正确。](https://issuetracker.google.com/issues/70444558 "Google Issue") 86 | 87 | **5. 版本记录** 88 | 89 | **v1.3.5** `2021.02.02` 细节调整,底层类改为AppCompatXXX。 90 | 91 | **v1.3.3** `2019.11.22` 修复默认背景Drawable错误。 92 | 93 | **v1.3.3** `2019.07.05` 文字支持无极加粗。 94 | 95 | **v1.3.2** `2019.05.27` 背景支持颜色和图片混搭组合。 96 | 97 | **v1.3.1** `2019.01.03` 支持点击背景添加遮罩层效果。 98 | 99 | **v1.3.0** `2018.12.28` 支持更多属性字段,细化更多状态属性。 100 | 101 | **v1.2.1** `2018.02.09` 修正代码逻辑判断。 102 | 103 | **v1.2.0** `2017.12.12` 发布1.2.0版本。 104 | 105 | ## License ## 106 | 107 | Licensed under the MIT License, see the [LICENSE](https://github.com/uccmawei/ColorView/blob/master/LICENSE) for copying permission. 108 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.2' 10 | classpath "com.github.panpf.bintray-publish:bintray-publish:1.0.0" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | } 19 | 20 | tasks.withType(Javadoc) { 21 | options { 22 | encoding "UTF-8" 23 | charSet 'UTF-8' 24 | links "http://docs.oracle.com/javase/7/docs/api" 25 | } 26 | } 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/demo.png -------------------------------------------------------------------------------- /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 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | 21 | # gradlew clean build bintrayUpload -PbintrayUser=*** -PbintrayKey=*** -PdryRun=false 22 | 23 | # systemProp.http.proxyHost=127.0.0.1 24 | # systemProp.http.proxyPort=10809 25 | # systemProp.https.proxyHost=127.0.0.1 26 | # systemProp.https.proxyPort=10809 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uccmawei/ColorView/20e06f77002fcc876e3e4f9d899157378adaeb33/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 02 11:14:50 CST 2021 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-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':ColorViewDemo', ':ColorViewLib' 2 | --------------------------------------------------------------------------------