Files
donghongyu fcd4b3b6a9 「Update」
1、增加皮肤包校验后删除其它皮肤包的操作
2024-10-15 19:29:57 +08:00

67 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### 换肤SDK
#### 使用方式
```java
public class MoGoApplication extends MultiDexApplication {
private static final String TAG = "MoGoApplication";
@Override
public void onCreate() {
super.onCreate();
// 初始化动态换肤SDK
SkinManager.init(this);
}
}
```
##### 基础控件0改动完成资源替换只需要保持使用的「资源文件drawable、string、color等」皮肤包与APP中保持一致即可
TextView 控件的静态文字一定要用string.xml 的方式引用文字显示
例如:
```xml
<TextView
android:id="@+id/tvDevicesId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/devicesId"
android:textColor="@color/colorAccent"
android:textSize="20dp" />
```
##### 如果代码中动态控制了 ImageView 的 src、background 一定要在 XML 中替换成 SkinImageView.java
##### 代码中动态获取资源设置:图片、文字、颜色
```java
// 获取颜色
SkinResources.getInstance().getColor(resId);
// 获取图片
SkinResources.getInstance().getDrawable(resId);
// 获取文字
SkinResources.getInstance().getString(resId);
// 获取指定的资源id
SkinResources.getInstance().getIdentifier(resId);
// 获取指定的Raw资源 InputStream
SkinResources.getInstance().getRawInputStream(resId);
// 获取指定的Raw资源的byte[]
SkinResources.getInstance().getRawResourceBytes(resId);
```
#### 手动控制切换皮肤
```java
Skin skin = new Skin(
// 皮肤包 MD5 用于文件损坏校验的
"d5493244467d3970834e42dc1a6f07c9",
// 皮肤文件名称
"app-skin-debug.skin",
// 外网可访问的文件服务器地址
"https://carlife-static-1255510688.cos.ap-beijing.myqcloud.com/MoGoEagleEye/app-skin-debug.skin");
// 换肤
SkinManager.getInstance().selectSkin(this, skin);
// 还原
SkinManager.getInstance().loadSkin("");
```