Back to Android Skin Support

Android-skin-support

docs/README.md

1.2.0-design-v1.2.0-cardview-v1.2.0-release8.2 KB
Original Source

Android-skin-support

中文 | In English

Android-skin-support is an easy skin framework to use for Android. The best case, Only one line of code to integrate the framework.

java
SkinCompatManager.withoutActivity(this).loadSkin();

Now, you have a strong skinning feature. What you need to do is make a skin.

Table of Contents

Gradle Dependencies

The Gradle Dependency is available via jCenter,

For the latest version, please refer to change log

Add dependencies for AndroidX

xml
implementation 'skin.support:skin-support:4.0.5'                   // skin-support
implementation 'skin.support:skin-support-appcompat:4.0.5'         // skin-support basic widget
implementation 'skin.support:skin-support-design:4.0.5'            // skin-support-design material design support [selectable]
implementation 'skin.support:skin-support-cardview:4.0.5'          // skin-support-cardview CardView support [selectable]
implementation 'skin.support:skin-support-constraint-layout:4.0.5' // skin-support-constraint-layout ConstraintLayout support [selectable]

Add dependencies for support libraries

xml
implementation 'skin.support:skin-support:3.1.4'                   // skin-support basic widget
implementation 'skin.support:skin-support-design:3.1.4'            // skin-support-design material design support [selectable]
implementation 'skin.support:skin-support-cardview:3.1.4'          // skin-support-cardview CardView support [selectable]
implementation 'skin.support:skin-support-constraint-layout:3.1.4' // skin-support-constraint-layout ConstraintLayout support [selectable]

Integration

Initialization

Only one line of code to integrate the framework.

java
@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();
}

If your Activity inherits from AppCompatActivity, you need to override the getDelegate() method.

java
@NonNull
@Override
public AppCompatDelegate getDelegate() {
    return SkinAppCompatDelegateImpl.get(this, this);
}

Load Skin

java
// Load the specified skin
SkinCompatManager.getInstance().loadSkin("new.skin"[, SkinLoaderListener], int strategy);

// restore default skin
SkinCompatManager.getInstance().restoreDefaultTheme();

Custom View skin support

  1. Implement the SkinCompatSupportable interface

  2. Apply skin resource in the applySkin method

  3. Resolve the skin resource id in the constructor

Make a skin

BuildIn Skin:

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:

java
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

Plug-in Skin:

New Android Application Project

Put the skin resources into the res directory

If the original window background is

colors.xml

xml
<color name="background">#ffffff</color>

for night-mode you can add this in the skin-night project

colors.xml

xml
<color name="background">#000000</color>

Generated apk is the skin package

You can rename night.apk to night.skin by yourself.

Load plug-in skin package

You can put the skin package into the assets/skins directory.

java
SkinCompatManager.getInstance().loadSkin("night.skin", SkinCompatManager.SKIN_LOADER_STRATEGY_ASSETS);

Or you can customize the loading strategy:

For example:

Inherit from SkinSDCardLoader,Override the getSkinPathgetType methods。

java
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

java
SkinCompatManager.withoutActivity(this).addStrategy(new CustomSDCardLoader());

Use this strategy to load skin:

java
SkinCompatManager.getInstance().loadSkin("night.skin", null, CustomSDCardLoader.SKIN_LOADER_STRATEGY_SDCARD);

Who use it

If you want to list your apk here. Welcome to commit pull request or Contact the author.

<table align="center"> <tr align="center"> <td></td> <td></td> <td></td> <td></td> </tr> <tr align="center">        <td><b><a href="https://k.sohu.com/">sohu newsclient lite</a></b></td>        <td><b><a href="http://www.iyuji.cn/iyuji/home">voice note</a></b></td>        <td><b><a href="https://news.qoo-app.com/">qoo app</a></b></td>        <td><b><a href="http://www.dwnews.com/">dwnews</a></b></td> </tr> </table>

About Author

Pengfeng Wang(王鹏锋)

email: [email protected]

License MIT