An android skin change framework
Load custom ui style from skin package
api("io.github.hellogoogle2000:android-skinner:1.0.0")
suggest calling after Application#onCreate
SkinnerKit.init(application)
call before apply this skin
SkinnerKit.installSkin(assets.open("skin.apk"), "skinner")
suggest calling before Activity#onCreate
SkinnerKit.installSkinnerFactory(activity)
recall Activity#setContentView
to take effect
SkinnerKit.loadSkin("skinner")
recall Activity#setContentView
to take effect
SkinnerKit.setSkinMode(SkinnerValues.SKIN_MODE_DARK)
recall Activity#setContentView
to take effect
SkinnerKit.loadSkin(SkinnerValues.SKIN_NAME_DEFAULT)
SkinnerKit.setSkinMode(SkinnerValues.SKIN_MODE_DEFAULT)
- add skin namespace
- specify provider
- dynamic resource should named end with
_skinnable
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:skin="http://schemas.android.com/skin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color_01_skinnable"
android:gravity="center"
android:orientation="vertical"
android:padding="30dp">
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/icon_app_skinnable"
skin:provider="BasicAttributeSkinner" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="Hello"
android:textColor="@color/text_color_01_skinnable"
android:textSize="16dp"
skin:provider="BasicAttributeSkinner" />
</LinearLayout>
due to android technical limit
skinner only support three skinnable attribute by default
background, src, and textColor
you can create your own provider to introduce more customization
take a reference to BasicAttributeSkinner
, that work is just simple
object CustomAttributeSkinner : BaseSkinnerProvider()
SkinnerProvidersFactory.registerViewProvider(CustomAttributeSkinner)
create an empty android application project
keep application id same with the origin one
if your skin have more than one mode, create a mode folder additionally
mode folder named as res-mode
, corresponding resource named as xxx_skinnable_mode
plugins {
id("com.android.application")
}
android {
compileSdk = 34
defaultConfig {
namespace = "com.android.app"
applicationId = "com.android.app"
minSdk = 30
}
sourceSets {
getByName("main").res.srcDirs("src/main/res-dark")
}
}
just like build an android apk
run Build - Build APK
, then you will get a skin apk in build/output
directory
install it to your application spaces as mentioned above
for more detailed confusion, take a look at sample app
this is actually a simple and concise library, I believe you can do it
Good Job, Baby !