├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── encodings.xml ├── gradle.xml ├── misc.xml └── runConfigurations.xml ├── ColorPrefUtil.gif ├── ColorPrefUtilLogo.png ├── ColorPrefUtil_sample2.gif ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── akndmr │ │ └── github │ │ └── io │ │ └── colorprefutil │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── akndmr │ │ │ └── github │ │ │ └── io │ │ │ └── colorprefutil │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_assignment.xml │ │ └── 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 │ └── akndmr │ └── github │ └── io │ └── colorprefutil │ └── ExampleUnitTest.java ├── build.gradle ├── colorprefutil ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── akndmr │ │ └── github │ │ └── io │ │ └── colorprefutil │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── akndmr │ │ │ └── github │ │ │ └── io │ │ │ └── colorprefutil │ │ │ └── ColorPrefUtil.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── akndmr │ └── github │ └── io │ └── colorprefutil │ └── ExampleUnitTest.java ├── 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/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /ColorPrefUtil.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akndmr/ColorPrefUtil/6bc483bfe6f3f1602ef3fe27287a7cbd94a1fde5/ColorPrefUtil.gif -------------------------------------------------------------------------------- /ColorPrefUtilLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akndmr/ColorPrefUtil/6bc483bfe6f3f1602ef3fe27287a7cbd94a1fde5/ColorPrefUtilLogo.png -------------------------------------------------------------------------------- /ColorPrefUtil_sample2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akndmr/ColorPrefUtil/6bc483bfe6f3f1602ef3fe27287a7cbd94a1fde5/ColorPrefUtil_sample2.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Akın Demir 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 | # ColorPrefUtil 2 | 3 |
4 | ColorPrefUtil for Android 5 |
6 | Easily change theme & background or text colors of views&layouts. [API >= 19] 7 |
8 |
9 | 10 | ![Release](https://jitpack.io/v/akndmr/ColorPrefUtil.svg) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-ColorPrefUtil-green.svg?style=flat )]( https://android-arsenal.com/details/1/7502 ) ![](https://img.shields.io/github/license/akndmr/colorprefutil.svg?style=flat) ![](https://img.shields.io/github/stars/akndmr/colorprefutil.svg?colorB=orange&style=flat) ![](https://img.shields.io/github/languages/top/akndmr/ColorPrefUtil.svg?style=flat) ![](https://img.shields.io/github/languages/code-size/akndmr/ColorPrefUtil.svg?style=flat) ![](https://img.shields.io/github/issues-raw/akndmr/colorprefutil.svg?style=flat) 11 | 12 |
13 | 14 | ------------ 15 | 16 | 17 | **Sample Preview:** 18 | 19 | ![ColorPrefUtil sample gif](https://raw.githubusercontent.com/akndmr/ColorPrefUtil/master/ColorPrefUtil.gif) 20 | 21 | 22 | ------------ 23 | 24 | 25 | ## **Setup** 26 | 27 | **Gradle** 28 | 29 | **Step 1.** Add the JitPack repository to your build file 30 | 31 | Add it in your root build.gradle at the end of repositories: 32 | ``` 33 | allprojects { 34 | repositories { 35 | ... 36 | maven { url 'https://jitpack.io' } 37 | } 38 | } 39 | ``` 40 | 41 | **Step 2.** Add the dependency 42 | ``` 43 | dependencies { 44 | implementation 'com.github.akndmr:ColorPrefUtil:1.0.1' 45 | } 46 | ``` 47 | 48 | ------------ 49 | 50 | 51 | ## [](https://github.com/akndmr/ColorPrefUtil/blob/master/README.md#usage)**Usage** 52 | 53 | For a complete sample, check **app** folder. 54 | 55 | #### [](https://github.com/akndmr/ColorPrefUtil/blob/master/README.md#changing-theme)**Changing Theme** 56 | 57 | First, you need to set different styles for different color themes - if you want to change theme(setTheme(R.style.id)). 58 | 59 | **styles.xml** 60 | 61 | 67 | 68 | 73 | 74 | **MainActivity.java** 75 | 76 | @Override 77 | protected void onCreate(Bundle savedInstanceState) { 78 | super.onCreate(savedInstanceState); 79 | 80 | // Set theme before setContentView 81 | mSharedPreferences = getSharedPreferences(PREF_COLOR, MODE_PRIVATE); 82 | int themeSelected = mSharedPreferences.getInt(THEME_SELECTED, R.style.AppTheme); 83 | ColorPrefUtil.changeThemeStyle(this, themeSelected); 84 | 85 | setContentView(R.layout.activity_main); 86 | 87 | //... 88 | } 89 | 90 | 91 | 92 | ------------ 93 | 94 | 95 | #### [](https://github.com/akndmr/ColorPrefUtil/blob/master/README.md#changing-backgroundcolor-of-single-or-all-views)**Changing BackgroundColor of Single View and All Views** 96 | 97 | **MainActivity.java** 98 | 99 | int selectedBackgroundColorId; 100 | 101 | @Override 102 | protected void onCreate(Bundle savedInstanceState) { 103 | super.onCreate(savedInstanceState); 104 | 105 | // Get selected colorId from preferences, if null, use default background color(colorPrimary) 106 | selectedBackgroundColorId = mSharedPreferences.getInt(COLOR_SELECTED, R.color.colorPrimary); 107 | 108 | // Single view 109 | mButton = findViewById(R.id.button); 110 | ColorPrefUtil.changeBackgroundColorOfSingleView(this, mButton, selectedBackgroundColorId); 111 | 112 | // All views inside parent layout 113 | mConstraintLayout = findViewById(R.id.cl_container); 114 | ColorPrefUtil.changeBackgroundColorOfChildViews(this, mConstraintLayout, selectedBackgroundColorId); 115 | } 116 | 117 | 118 | ------------ 119 | 120 | 121 | **Changing Text Color of Single View and All Views** 122 | 123 | // All views inside given parent layout 124 | ColorPrefUtil.changeTextColorOfChildViews(this, mConstraintLayout, textColorId, hintColorId); 125 | 126 | // Single view 127 | ColorPrefUtil.changeTextColorOfSingleView(this, mTextView, textColorId, hintColorId); 128 | 129 | ------------ 130 | 131 | 132 | **Changing Tint Color of Icons (ImageView)** 133 | 134 | ColorPrefUtil.changeTintColorOfIcon(this, mImageViewIcon, iconTintColorId); 135 | 136 | ------------ 137 | 138 | 139 | **Changing Background Drawable of Single View and All Views** 140 | *You can set custom background drawables for views.* 141 | 142 | ColorPrefUtil.changeBackgroundDrawableOfChildViews(this, mConstraintLayout, backgroundColorId); 143 | ColorPrefUtil.changeBackgroundDrawableOfSingleView(this, mButton, backgroundDrawableId); 144 | 145 | ------------ 146 | 147 | 148 | **Changing Item Colors of NavigationView** 149 | *Change icon tint color and text colors of Nav view.* 150 | 151 | ColorPrefUtil.changeColorOfItemsOfNavView(mNavigationView, iconColorId, textColorId); 152 | 153 | ------------ 154 | 155 | 156 | **Changing Colors of TabLayout** 157 | *Change TabLayout background, selected tab, indicator, text colors.* 158 | 159 | ColorPrefUtil.changeColorOfTabLayout(this, mTabLayout, backgroundColorId, selectedTabColorId, indicatorColorId, textColorId); 160 | 161 | 162 | 163 | ------------ 164 | 165 |
166 | **LICENSE** 167 | 168 | MIT License 169 | 170 | Copyright (c) 2019 Akın Demir 171 | 172 | Permission is hereby granted, free of charge, to any person obtaining a copy 173 | of this software and associated documentation files (the "Software"), to deal 174 | in the Software without restriction, including without limitation the rights 175 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 176 | copies of the Software, and to permit persons to whom the Software is 177 | furnished to do so, subject to the following conditions: 178 | 179 | The above copyright notice and this permission notice shall be included in all 180 | copies or substantial portions of the Software. 181 | 182 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 183 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 184 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 185 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 186 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 187 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 188 | SOFTWARE. 189 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "akndmr.github.io.colorprefutil" 7 | minSdkVersion 19 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | vectorDrawables.useSupportLibrary = true 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | buildToolsVersion '28.0.3' 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(include: ['*.jar'], dir: 'libs') 25 | implementation 'com.android.support:appcompat-v7:28.0.0' 26 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 27 | testImplementation 'junit:junit:4.12' 28 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 29 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 30 | implementation project(path: ':colorprefutil') 31 | implementation 'com.android.support:recyclerview-v7:28.0.0' 32 | implementation 'com.android.support:design:28.0.0' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/akndmr/github/io/colorprefutil/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package akndmr.github.io.colorprefutil; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("akndmr.github.io.colorprefutil", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/akndmr/github/io/colorprefutil/MainActivity.java: -------------------------------------------------------------------------------- 1 | package akndmr.github.io.colorprefutil; 2 | 3 | import android.content.SharedPreferences; 4 | import android.support.constraint.ConstraintLayout; 5 | import android.support.design.widget.TabLayout; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 17 | 18 | public static final String PREF_COLOR = "pref_color"; 19 | public static final String COLOR_SELECTED = "color_selected"; 20 | public static final String COLOR_LIGHT_SELECTED = "color_light_selected"; 21 | public static final String THEME_SELECTED = "theme_selected"; 22 | 23 | int colorSelected, colorSelectedLight; 24 | 25 | SharedPreferences mSharedPreferences; 26 | SharedPreferences.Editor editor; 27 | 28 | Button mButton, mButtonAsphalt, mButtonBlue, mButtonRed, mButtonThemeGreen, mButtonThemePurple; 29 | ConstraintLayout mConstraintLayout; 30 | TextView mTextView; 31 | EditText mEditText; 32 | ImageView mImageViewIcon; 33 | TabLayout mTabLayout; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | 39 | // Set theme before setContentView 40 | mSharedPreferences = getSharedPreferences(PREF_COLOR, MODE_PRIVATE); 41 | int themeSelected = mSharedPreferences.getInt(THEME_SELECTED, R.style.AppTheme); 42 | ColorPrefUtil.changeThemeStyle(this, themeSelected); 43 | 44 | setContentView(R.layout.activity_main); 45 | 46 | editor = mSharedPreferences.edit(); 47 | colorSelected = mSharedPreferences.getInt(COLOR_SELECTED, R.color.colorPrimary); 48 | colorSelectedLight = mSharedPreferences.getInt(COLOR_LIGHT_SELECTED, R.color.textColor); 49 | 50 | 51 | bindViews(); 52 | bindListeners(); 53 | 54 | ColorPrefUtil.changeColorOfTabLayout(this, mTabLayout, colorSelected, colorSelectedLight, R.color.textColor, R.color.textColor); 55 | // ColorPrefUtil.changeTextColorOfChildViews(this, mConstraintLayout, colorSelected, colorSelectedLight); 56 | ColorPrefUtil.changeTextColorOfSingleView(this, mTextView, colorSelected, colorSelectedLight); 57 | ColorPrefUtil.changeTextColorOfSingleView(this, mEditText, colorSelected, colorSelectedLight); 58 | ColorPrefUtil.changeTintColorOfIcon(this, mImageViewIcon, colorSelected); 59 | ColorPrefUtil.changeBackgroundColorOfSingleView(this, mButton, colorSelected); 60 | } 61 | 62 | public void bindViews(){ 63 | mTabLayout = findViewById(R.id.tabLayout); 64 | mConstraintLayout = findViewById(R.id.cl_container); 65 | mImageViewIcon = findViewById(R.id.imageView); 66 | mButtonAsphalt = findViewById(R.id.btnAsphalt); 67 | mButtonBlue = findViewById(R.id.btnBlue); 68 | mButtonRed = findViewById(R.id.btnRed); 69 | mButtonThemeGreen = findViewById(R.id.btnThemeGreen); 70 | mButtonThemePurple = findViewById(R.id.btnThemePurple); 71 | mButton = findViewById(R.id.button); 72 | mTextView = findViewById(R.id.textView); 73 | mEditText = findViewById(R.id.editText); 74 | } 75 | 76 | public void bindListeners(){ 77 | mButtonAsphalt.setOnClickListener(this); 78 | mButtonBlue.setOnClickListener(this); 79 | mButtonRed.setOnClickListener(this); 80 | mButtonThemeGreen.setOnClickListener(this); 81 | mButtonThemePurple.setOnClickListener(this); 82 | } 83 | 84 | @Override 85 | public void onClick(View v) { 86 | 87 | switch (v.getId()){ 88 | case R.id.btnAsphalt: 89 | editor.putInt(COLOR_SELECTED, R.color.colorAsphalt); 90 | editor.putInt(COLOR_LIGHT_SELECTED, R.color.colorAsphaltLight); 91 | editor.commit(); 92 | //showMessage("btnAsphalt"); 93 | recreate(); 94 | break; 95 | case R.id.btnBlue: 96 | editor.putInt(COLOR_SELECTED, R.color.colorBlue); 97 | editor.putInt(COLOR_LIGHT_SELECTED, R.color.colorBlueLight); 98 | editor.commit(); 99 | //showMessage("btnBlue"); 100 | recreate(); 101 | break; 102 | case R.id.btnRed: 103 | editor.putInt(COLOR_SELECTED, R.color.colorRed); 104 | editor.putInt(COLOR_LIGHT_SELECTED, R.color.colorRedLight); 105 | editor.commit(); 106 | //showMessage("btnRed"); 107 | recreate(); 108 | break; 109 | case R.id.btnThemeGreen: 110 | editor.putInt(THEME_SELECTED, R.style.AppTheme); 111 | editor.commit(); 112 | //showMessage("Green theme selected"); 113 | recreate(); 114 | break; 115 | case R.id.btnThemePurple: 116 | editor.putInt(THEME_SELECTED, R.style.AppThemePurple); 117 | editor.commit(); 118 | //showMessage("Purple theme selected"); 119 | recreate(); 120 | break; 121 | 122 | } 123 | } 124 | 125 | private void showMessage(String message){ 126 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_assignment.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 21 | 22 |