In English | 中文
Android-skin-support is an easy to use skin framework for Android. The best case, Only one line of code to integrate the framework.
SkinCompatManager.withoutActivity(this).loadSkin();
Now, you have a strong skinning feature. What you need to do is make a skin.
The Gradle Dependency is available via jCenter,
Add dependencies directly, For the latest version, please refer to change log
compile 'skin.support:skin-support:2.2.2' // skin-support basic widget
compile 'skin.support:skin-support-design:2.2.2' // skin-support-design material design support [selectable]
compile 'skin.support:skin-support-cardview:2.2.2' // skin-support-cardview CardView support [selectable]
compile 'skin.support:skin-support-constraint-layout:2.2.2' // skin-support-constraint-layout ConstraintLayout support [selectable]
Only one line of code to integrate the framework.
@Override
public void onCreate() {
super.onCreate();
SkinCompatManager.withoutActivity(this) // Basic Widget support
.addInflater(new SkinMaterialViewInflater()) // material design support [selectable]
.addInflater(new SkinConstraintViewInflater()) // ConstraintLayout support [selectable]
.addInflater(new SkinCardViewInflater()) // CardView v7 support [selectable]
.setSkinStatusBarColorEnable(false) // Disable statusBarColor skin support,default true [selectable]
.setSkinWindowBackgroundEnable(false) // Disable windowBackground skin support,default true [selectable]
.loadSkin();
}
// Load the specified skin
SkinCompatManager.getInstance().loadSkin("new.skin"[, SkinLoaderListener], int strategy);
// restore default skin
SkinCompatManager.getInstance().restoreDefaultTheme();
-
Implement the
SkinCompatSupportable
interface -
Apply skin resource in the applySkin method
-
Resolve the skin resource id in the constructor
-
Custom View can inherit directly from existing widget, such as
SkinCompatView
,SkinCompatLinearLayout
, etc.eg: CustomTextView
-
if you don't want to inherit from existing widget.
eg: CustomTextView2
-
If you need to skin the custom attributes.
// such as AutoCompleteTextView's R.attr.popupBackground attribute
-
If you need to use third-party library.
// need to use https://github.com/hdodenhof/CircleImageView widget
BuildIn Skin,if the skin name is night
; Add a resource that needs to be skinned with a suffix _night
or prefix night_
.
if the default resource is R.color.windowBackgroundColor
, then you can add a resource R.color.windowBackgroundColor_night
。
load buildIn skin:
SkinCompatManager.getInstance().loadSkin("night", SkinCompatManager.SKIN_LOADER_STRATEGY_BUILD_IN); // load by suffix
SkinCompatManager.getInstance().loadSkin("night", SkinCompatManager.SKIN_LOADER_STRATEGY_PREFIX_BUILD_IN); // load by prefix
If the original window background is
colors.xml
<color name="background">#ffffff</color>
for night-mode you can add this in the skin-night
project
colors.xml
<color name="background">#000000</color>
You can rename night.apk to night.skin by yourself.
You can put the skin package into the assets/skins directory.
SkinCompatManager.getInstance().loadSkin("night.skin", SkinCompatManager.SKIN_LOADER_STRATEGY_ASSETS);
Or you can customize the loading strategy:
For example:
Inherit from SkinSDCardLoader
,Rewrite the getSkinPath
、getType
methods。
public class CustomSDCardLoader extends SkinSDCardLoader {
public static final int SKIN_LOADER_STRATEGY_SDCARD = Integer.MAX_VALUE;
@Override
protected String getSkinPath(Context context, String skinName) {
return new File(SkinFileUtils.getSkinDir(context), skinName).getAbsolutePath();
}
@Override
public int getType() {
return SKIN_LOADER_STRATEGY_SDCARD;
}
}
Register this strategy in Application's onCreate
SkinCompatManager.withoutActivity(this).addStrategy(new CustomSDCardLoader());
Use this strategy to load skin:
SkinCompatManager.getInstance().loadSkin("night.skin", null, CustomSDCardLoader.SKIN_LOADER_STRATEGY_SDCARD);
Pengfeng Wang(王鹏锋)
email: ximsfei@gmail.com