Skingchange_ex里面有和涉及的换肤种类有如下
- background 更换背景色
- textColor 更换字体颜色
- src 更换图片资源,(需要准备需要换肤后的图片)
- divider 更换ListView中间的分割线颜色
- ImageViewColor 更换图片颜色(需要换肤的对象是Vector类型的)
- background_d 更换背景色 (换肤的资源)
- background_c 更换背景色(更换颜色)
- SelectorColor 选择器换肤
- SelectortextColor 选择器字体颜色换肤
- shapeSolidColor 单独更换shapeSolidColor的颜色
- shapeStrokeColor 单独更换shape 线框的颜色
- shapeStrokeColorFONT 单独更换shape 线框和字体的颜色
- shapeGradientColor 单独更换渐变的颜色
- shapeGradientStrokeColor 单独更换渐变的颜色有边框
- shapeeGradientColorFONT_S 单独更换渐变的边框和字体颜色
使用效果
使用方式和功能介绍如下
1.background
使用格式
android:tag="skin:color_theme:background"
这是大神原有的,但是这里我不建议大家使用,而是推荐大家使用
background_d和background_c,原因是,原来的先是判断是有换肤的资源,有则更换资源背景,没有则更换颜色背景,这样容易把一些只需要换颜色的控件,换成资源了,比如,一个LinearLayout是想换背景图的,一个Button是想换背景颜色的,这样就容易两个换成同一种资源,或者是,不用同一种换背景色的写法,加以区分也可以。
使用方式
先在res文件夹下colors文件的有相应要换肤的颜色
<color name="colorPrimary">#03A9F4</color>
换肤后的颜色
<color name="colorPrimary_test">#A700EE</color>
在代码中进行换肤
SkinManager.getInstance().changeSkin("test");
控件中
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:background="@drawable/btn_sp_bg_2"
android:tag="skin:colorPrimaryDark:background"
/>
2.textColor
使用格式
android:tag="skin:color_theme:textColor"
注:这是使用同名颜色资源,要在color里有换肤的颜色
3.src
使用格式
android:tag="skin:color_theme:src"
注:这里换的同名资源,你要准备一个color_theme.png的图片,还要准备一个color_theme_test.png的图片
4.divider
使用格式
android:tag="skin:color_theme:divider"
注:这里使用的是资源文件,要有drawbl文件才能换肤成功
5.ImageViewColor
使用格式
android:tag="skin:color_theme:ImageViewColor"
注:这里必须要使用的是Vector类型的图片文件
6.background_d
使用格式
android:tag="skin:color_theme:background_d"
注:这里换的同名资源,你要准备一个color_theme.png的图片,还要准备一个color_theme_test.png的图片
7.background_c
使用格式
android:tag="skin:color_theme:background_c"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
8.SelectorColor
使用格式
android:tag="skin:color_theme:SelectorColor"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
添加_set_1 颜色值
换肤前的选择器默认颜色
<color name="colorPrimary_set_1">#A700EE</color>
换肤后的选择器的颜色
<color name="colorPrimary_set_1_test">#A700EE</color>
为true是空心的,为fasle是实心的
9.SelectortextColor
使用格式
android:tag="skin:color_theme:SelectortextColor"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
这里的要求和上面的SelectorColor是一样的,都需要在color中添加_set_1.
为true是默认的颜色,为false是变色的
10.shapeSolidColor
使用格式
android:tag="skin:color_theme:shapeSolidColor"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
单独更换shapeSolidColor的颜色
11.shapeStrokeColor
使用格式
android:tag="skin:color_theme:shapeStrokeColor"
注:单独更换shapeStroke的颜色
12.shapeStrokeColorFONT
使用格式
android:tag="skin:color_theme:shapeStrokeColorFON"
注:单独更换shape 线框和字体的颜色
13.shapeGradientColor
使用格式
android:tag="skin:color_theme:shapeGradientColor"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
单独更换渐变的颜色
要在color里添加_str和_end。这里只考虑两种渐变没有中间渐变,有需求得,请下载源码自己加或者和我联系。
渐变开始,渐变结束两种颜色
渐变换肤前颜色
<color name="colorPrimary_str">#590BE4</color>
<color name="colorPrimary_end">#FFC107</color>
渐变换肤后颜色
<color name="colorPrimary_str_test">#E42113</color>
<color name="colorPrimary_end_test">#09DDF8</color>
14.shapeGradientStrokeColor
使用格式
android:tag="skin:color_theme:shapeGradientStrokeColor"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
单独更换渐变的颜色有边框
要求同上
15.shapeeGradientColorFONT_S
使用格式
android:tag="skin:color_theme:shapeeGradientColorFONT_S"
注:这里必须要使用的是颜色,要在Color里有相应的颜色
单独更换渐变的边框和字体颜色
要求同上
补充一下使用方式
Step.1 引用jar包
在项目的根目录下的build.gradle 添加jitpack
repositories {
maven { url "https://jitpack.io" }
google()
jcenter()
}
在项目的app目录下的build.gradle 添加jitpack
dependencies {
implementation 'com.github.hkdoke:changeskin_ex:0.1'
}
Step.2 初始化
在Application中onCreate的方法初始化控件
SkinManager.getInstance().init(this);
在Activity中的onCreate方法注册
SkinManager.getInstance().register(this);
在Activity中的onDestroy方法销毁
SkinManager.getInstance().unregister(this);
注:也可以写在BaseActivity中统一注册和引用
Step.3 使用
在需要换肤的控件的xml中
android:tag="skin:color_theme:textColor"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:onClick="chagex"
android:textColor="@color/color_theme"
android:tag="skin:color_theme:textColor"
/>
在colors中需要添加换肤后的颜色
换肤前的颜色
<color name="color_theme">#03DAC5</color>
换肤后的颜色
<color name="color_theme_red">#DA032E</color>
最后一键换肤
public void chagex(View view) {
if (isChange) {
isChange = false;
SkinManager.getInstance().changeSkin("red");
} else {
isChange = true;
SkinManager.getInstance().changeSkin("");
}
}
最后附上项目地址
[传送门]github.com/chenStill/c…
也附上鸿洋大神的项目地址
[Changeskin]github.com/hongyangAnd…