# MySkin
**Repository Path**: code_tjf/MySkin
## Basic Information
- **Project Name**: MySkin
- **Description**: 一个测试换肤框架的demo,具体使用参考readme.md
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-03-22
- **Last Updated**: 2021-03-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Android换肤
CSDN博客:
[Android 动态式换肤框架1-setContentView源码分析:](https://blog.csdn.net/hongxue8888/article/details/95494195),[Android 动态式换肤框架2-实现背景替换:](https://blog.csdn.net/hongxue8888/article/details/95390639),
[Android 动态式换肤框架3-Fragment、状态栏换肤:](https://blog.csdn.net/hongxue8888/article/details/96310094),[Android 动态式换肤框架4-自定义控件换肤:](https://blog.csdn.net/hongxue8888/article/details/96476296)
Github:[https://github.com/345166018/WangyiSkin/tree/master/HxSkin](https://github.com/345166018/WangyiSkin/tree/master/HxSkin)
#### 介绍
一个换肤框架 支持全局更换字体及局部更换
## 使用方式
1.引入该 library,并在build.gradle中添加依赖该项目
```
dependencies {
...
implementation project(':lib_skin')
}
```
2.在app项目的Application中进行初始化
```
SkinManager.init(Application);
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SkinManager.init(this);
}
}
```
3.在需要更换皮肤的地方使用
```
SkinManager.getInstance().loadSkin("apkPath");
```
进行更换皮肤,需要还原的时候直接将apkPath置空,即
```
SkinManager.getInstance().loadSkin(null);
```
更换字体颜色 自定义View 的 实现换肤接口 SkinViewSupport中的applySkin()方法;
示例
```
if (backgroundColor != 0) {
int color = SkinResources.getInstance().getColor(R.color.huaWeiClockBackgroundColor);
backgroundPaint.setColor(color);
invalidate();
}
```
字体放在assets 下的font
在 values 下的strings 下添加 示例如下 字体样式 font下的都是字体 可根据字体更改
```
font/specified.ttf
font/global.ttf
```
皮肤包的下的
在 values 下的strings 下添加 示例如下 字体样式 font下的都是字体 可根据字体更改
```
font/specified.ttf
font/specified.ttf
font/xingkai.ttf
```
更换字体 自定义View 的 实现换肤接口 SkinViewSupport中的applySkin()方法
在自定义View中添加自定义字体属性
在values 下的strings 的typeface_3 该值可以为空但必须有该属性
在皮肤包下设置要更换的字体即可在 values 下的strings 的typeface_3
例如
```
font/xingkai.ttf
```
在xml中必须写该自定义的属性
```
app:huaWeiClockTimeTextTypeface="@string/typeface_3"
```
如下:
```
timeTextTypefac = typedArray.getString(R.styleable.HuaWeiClock_huaWeiClockTimeTextTypeface);
if (TextUtils.isEmpty(timeTextTypefac)) {
Typeface typeface = SkinResources.getInstance().getTypeface(R.string.typeface_3);
timePaint.setTypeface(typeface);
invalidate();
}
```
全局更换字体 字体也是选择你需要的字体 typeface_1 对应不同的字体
更换字体都是修改values 下的strings 的 typeface_1 主项目下的
在styles 中的AppTheme主题下添加
```
- @string/typeface_1
```
皮肤包下的
在styles 中的AppTheme主题下添加
```
- @string/typeface_1
```