├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ruiyi │ │ └── chengpifu │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── skin.apk │ ├── java │ │ └── com │ │ │ └── ruiyi │ │ │ └── chengpifu │ │ │ ├── BaseApp.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher_round.png │ │ └── main_bg.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher_round.png │ │ └── main_bg.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher_round.png │ │ └── main_bg.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher_round.png │ │ └── main_bg.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher_round.png │ │ └── main_bg.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── ruiyi │ └── chengpifu │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── skin_core ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── ruiyi │ └── skin_core │ └── ExampleInstrumentedTest.java ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── ruiyi │ │ └── skin_core │ │ ├── SkinAttribute.java │ │ ├── SkinFactory.java │ │ ├── SkinManager.java │ │ └── uitls │ │ ├── SkinActivityLifecycle.java │ │ ├── SkinPreference.java │ │ ├── SkinResourcess.java │ │ └── SkinThemeUitls.java └── res │ └── values │ └── strings.xml └── test └── java └── com └── ruiyi └── skin_core └── ExampleUnitTest.java /.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 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | Android API 18 Platform 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # skin 2 | 市面上对数的App都提供换肤功能,这里暂且不讲白天和夜间模式 3 | 4 | 下图是网易云音乐的换肤功能 5 | 6 | ![经典](https://upload-images.jianshu.io/upload_images/11195468-7e7c93b52d7af746.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/118/format/webp) 7 | 8 | ![黑](https://upload-images.jianshu.io/upload_images/11195468-c021f0c829864ba7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/118/format/webp) 9 | 10 | 换肤其实就是替换资源(文字、颜色、图片等) 11 | ### 一、换肤模式: 12 | ``` 13 | 1.内置换肤 14 | 在Apk包中存在多种资源(图片、颜色值)用于换肤时候切换。 15 | 自由度低,apk文件大 一般用于没有其他需求的日间/夜间模式app 16 | 2.动态换肤 17 | 通过运行时动态加载皮肤包 18 | ``` 19 | ### 二、如何使用 20 | ``` 21 | //init 22 | public class BaseApp extends Application { 23 | @Override 24 | public void onCreate() { 25 | super.onCreate(); 26 | SkinManager.init(this); 27 | } 28 | } 29 | ``` 30 | ``` 31 | //loadSkin 32 | public void apply(View view) { 33 | SkinManager.getInstance().loadSkin("/sdcard/skin.apk"); 34 | } 35 | //restore 36 | public void restore(View view) { 37 | SkinManager.getInstance().loadSkin(""); 38 | } 39 | 40 | 41 | ``` 42 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | app.iml 3 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.ruiyi.chengpifu" 7 | minSdkVersion 19 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:0.5' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' 28 | implementation project(':skin_core') 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ruiyi/chengpifu/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ruiyi.chengpifu; 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() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ruiyi.chengpifu", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/assets/skin.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inPeige/skin/069d3ae586f82f6eba143f164f1bf58160f04b66/app/src/main/assets/skin.apk -------------------------------------------------------------------------------- /app/src/main/java/com/ruiyi/chengpifu/BaseApp.java: -------------------------------------------------------------------------------- 1 | package com.ruiyi.chengpifu; 2 | 3 | import android.app.Application; 4 | 5 | import com.ruiyi.skin_core.SkinManager; 6 | 7 | /** 8 | * Created by liupei on 2018/3/18. 9 | */ 10 | 11 | public class BaseApp extends Application { 12 | @Override 13 | public void onCreate() { 14 | super.onCreate(); 15 | SkinManager.init(this); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/ruiyi/chengpifu/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ruiyi.chengpifu; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | 11 | import com.ruiyi.skin_core.SkinManager; 12 | 13 | import java.io.File; 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | 18 | public class MainActivity extends Activity { 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | } 25 | 26 | public void apply(View view) { 27 | SkinManager.getInstance().loadSkin("/sdcard/skin.apk"); 28 | } 29 | 30 | public void restore(View view) { 31 | SkinManager.getInstance().loadSkin(""); 32 | } 33 | 34 | /** 35 | * 从assets目录下拷贝文件 36 | * 37 | * @param context 上下文 38 | * @param assetsFilePath 文件的路径名如:SBClock/0001cuteowl/cuteowl_dot.png 39 | * @param targetFileFullPath 目标文件路径如:/sdcard/SBClock/0001cuteowl/cuteowl_dot.png 40 | */ 41 | public static void copyFileFromAssets(Context context, String assetsFilePath, String targetFileFullPath) { 42 | Log.d("Tag", "copyFileFromAssets "); 43 | InputStream assestsFileImputStream; 44 | try { 45 | assestsFileImputStream = context.getAssets().open(assetsFilePath); 46 | copyFile(assestsFileImputStream, targetFileFullPath); 47 | } catch (IOException e) { 48 | Log.d("Tag", "copyFileFromAssets " + "IOException-" + e.getMessage()); 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | private static void copyFile(InputStream in, String targetPath) { 54 | try { 55 | FileOutputStream fos = new FileOutputStream(new File(targetPath)); 56 | byte[] buffer = new byte[1024]; 57 | int byteCount = 0; 58 | while ((byteCount = in.read(buffer)) != -1) {// 循环从输入流读取 59 | // buffer字节 60 | fos.write(buffer, 0, byteCount);// 将读取的输入流写入到输出流 61 | } 62 | fos.flush();// 刷新缓冲区 63 | in.close(); 64 | fos.close(); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | 70 | public void load(View view) { 71 | copyFileFromAssets(this, "skin.apk", "/sdcard/skin.apk"); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |