{"id":15027444,"url":"https://github.com/bilibili/magicasakura","last_synced_at":"2025-05-15T02:09:23.836Z","repository":{"id":45519779,"uuid":"61786082","full_name":"bilibili/MagicaSakura","owner":"bilibili","description":"MagicaSakura 是 Android 多主题框架。~ is an Android multi theme library which supporting both daily colorful theme and night theme. ","archived":false,"fork":false,"pushed_at":"2022-02-16T08:39:50.000Z","size":3043,"stargazers_count":3552,"open_issues_count":25,"forks_count":465,"subscribers_count":95,"default_branch":"master","last_synced_at":"2025-05-15T02:09:22.528Z","etag":null,"topics":["android-library","colorful","multi-theme","multicolor","svg","theme","vector"],"latest_commit_sha":null,"homepage":"http://app.bilibili.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bilibili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-23T07:54:59.000Z","updated_at":"2025-05-02T11:59:40.000Z","dependencies_parsed_at":"2022-07-18T08:17:04.948Z","dependency_job_id":null,"html_url":"https://github.com/bilibili/MagicaSakura","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2FMagicaSakura","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2FMagicaSakura/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2FMagicaSakura/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2FMagicaSakura/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bilibili","download_url":"https://codeload.github.com/bilibili/MagicaSakura/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259384,"owners_count":22040820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-library","colorful","multi-theme","multicolor","svg","theme","vector"],"created_at":"2024-09-24T20:06:26.634Z","updated_at":"2025-05-15T02:09:23.804Z","avatar_url":"https://github.com/bilibili.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![cover](https://raw.githubusercontent.com/xyczero/MagicaSakura/master/screenshot/magicasakura_cover.png)\n\n## MagicaSakura\n[ ![Download](https://api.bintray.com/packages/xyczero/maven/MagicaSakura/images/download.svg?version=0.1.9-beta3) ](https://bintray.com/xyczero/maven/MagicaSakura/0.1.9-beta3/link)\n\nMagicaSakura is an Android multi theme library which supporting both daily colorful theme and night theme.\n\n## Feature\n\n\u003e1. Support both the daily colorful theme and the night theme.\n\n\u003e2. Switch different theme without recreating activities.\n\n\u003e3. Provide TintXXX Widgets for adapting multi theme to be more convenient and fast.\n\n\u003e4. Just writie a drawable.xml or layout.xml can be automatically adapted to different theme styles.\n\n\u003e5. Offer backward-compatible versions of the Android system that can be used with 4.0.3 or higher.\n\n\u003e6. Support Vector Drawable with appcompat-v7.\n\n\u003e7. Easy to integrate to your app.\n\n## Demo\n\n![ScreenShot.gif](https://github.com/xyczero/MagicaSakura/blob/master/screenshot/magicasakura.gif)\n \n You can download the lastest sample apk from Google Play.\n\n\u003ca href=\"https://play.google.com/store/apps/details?id=com.bilibili.magicasakurademo\"\u003e\u003cimg src=\"https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png\" height=\"60\" data-canonical-src=\"https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n \n\n## Gradle Dependency\n```\ncompile 'com.bilibili:magicasakura:0.1.9-beta3@aar'\n```\n\n## Maven Dependency\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.bilibili\u003c/groupId\u003e\n  \u003cartifactId\u003emagicasakura\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.9-beta3\u003c/version\u003e\n  \u003ctype\u003eaar\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n \n  \n - **STEP1** : \n \n Define your app global theme color variates in values/color.xml, like as:\n ```xml\n \u003ccolor name=\"theme_color_primary\"\u003e#fb7299\u003c/color\u003e\n \u003ccolor name=\"theme_color_primary_dark\"\u003e#b85671\u003c/color\u003e\n \u003ccolor name=\"theme_color_primary_trans\"\u003e#99f0486c\u003c/color\u003e\n ```\n Must use these color variates in layout xml , color xml or drawable xml when these xml files need to be automatically adapted to different theme styles.\n If you use direct color value or other color variates, adapting different theme styles will be out of work.\n \n - **STEP2** :\n \n Implement ThemeUtils.switchColor interface in the app Applaction;\n You Define your own rules combining with the color variates(defining in Step 1) for switching different colors when choosing different themes.\n ```java\n public class MyApplication extends Application implements ThemeUtils.switchColor {\n      @Override\n      public void onCreate() {\n          super.onCreate();\n          //init\n          ThemeUtils.setSwitchColor(this);\n      }\n      \n      @Override\n      public int replaceColorById(Context context, @ColorRes int colorId) {\n        ...\n        if(ThemeHelper.getThemeId(context) == \"blue\"){\n            switch (colorId) {\n              // define in Step 1\n              case R.color.theme_color_primary:\n                return R.color.blue;\n                ...\n            }\n        ...\n      }\n\n      @Override\n      public int replaceColor(Context context, @ColorInt int originColor) {\n        if (ThemeHelper.isDefaultTheme(context)) {\n            return originColor;\n        }\n        ...\n      }\n }\n ```\n \n - **STEP3** :\n \n The library provides a series of TintXXX widgets which including most common android widgets.\n \n When some place in your app needs to adapter multi theme, you can use these TintXXX widgets **combining with the color variates(defining in Step 1)  or color xml(using the color variates) or drawable xml(the color variates)** , then they will be auto adapting.\n \n  - Drawable Xml\n    TintXXX widgets support common drawable xml tag, such as \u003cselector/\u003e, \u003citem/\u003e, \u003cshape/\u003e , \u003clayerlist/\u003e, \u003ccolor/\u003e and etc in drawable xml.\n  \n    (Note: when using not supporting drawable xml tag, just can't be adapted to multi theme)\n  \n    Specially, TintXXX widgets additional support directly tint drawable with app:drawableTint and app:drawableTintMode and set color alpha with android:alpha.\n  \n    Here is an example:\n    \n    ``` java\n    //drawable xml\n    //tint directly\n    \u003cselector\n      xmlns:android=\"http://schemas.android.com/apk/res/android\"\n      xmlns:app=\"http://schemas.android.com/apk/res-auto\"\u003e\n      \u003citem android:drawable=\"@drawable/icon \" android:state_pressed=\"true\" app:drawableTint=\"@color/theme_color_primary\" /\u003e\n      \u003citem android:drawable=\"@drawable/icon\" app:drawableTint=\"@color/gray_dark\" /\u003e\n    \u003c/selector\u003e\n    \n    ```\n\n\t\n    ```java\n    // set color alpha in color\n    \u003cselector xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n        \u003citem android:state_enabled=\"true\" android:state_pressed=\"true\"\u003e\n            \u003cshape\u003e\n              \u003ccorners android:radius=\"4dp\" /\u003e\n              \u003csolid android:color=\"@color/theme_color_primary_dark\" /\u003e\n            \u003c/shape\u003e\n        \u003c/item\u003e\n        \u003citem android:state_enabled=\"true\"\u003e\n            \u003cshape\u003e\n              \u003csolid android:color=\"@color/theme_color_primary\" /\u003e\n              \u003ccorners android:radius=\"4dp\" /\u003e\n            \u003c/shape\u003e\n        \u003c/item\u003e\n        \u003citem android:state_enabled=\"false\"\u003e\n            \u003cshape\u003e\n              \u003csolid android:alpha=\"0.3\" android:color=\"@color/theme_color_primary\" /\u003e\n              \u003ccorners android:radius=\"4dp\" /\u003e\n            \u003c/shape\u003e\n        \u003c/item\u003e\n    \u003c/selector\u003e\n    ```\n \n  - Layout Xml\n    TintXXX widgets can be tinted directly in layout xml that supporting most common android drawable attrs , such as background , src , drawableLeft, button and etc. \n    \n    (Note: when tinting directly in layout xml , must use the color variates(defining in Step 1), otherwise adapting different theme styles will be out of work)\n    \n    Here is an example:\n    \n    ```java\n    // shape_lock.xml\n    \u003cshape xmlns:android=\"http://schemas.android.com/apk/res/android\"\n        android:shape=\"rectangle\"\u003e\n        \u003csize android:width=\"1dp\" /\u003e\n        \u003csolid android:color=\"@color/theme_color_primary\" /\u003e\n        \u003cstroke android:color=\"@color/gray_dark\" /\u003e\n    \u003c/shape\u003e\n    \n    // TintTextView\n    // The selector_lock and selector_text is a ColorStateList\n    // The shape_lock is a shape drawable.\n    \u003ccom.bilibili.magicasakura.widgets.TintTextView\n\t     xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n\t     android:layout_width=\"wrap_content\"\n\t     android:layout_height=\"wrap_content\"\n\t     android:drawablePadding=\"@dimen/padding_half\"\n\t     android:drawableRight=\"@drawable/selector_lock\"\n\t     android:drwableLeft=\"@drawable/shape_lock\"\n\t     android:text=\"@string/textview_title\"\n\t     android:textColor=\"@color/selector_text\"\n\t     android:textSize=\"19sp\" \n\t     app:drawableRightTint=\"@color/selector_lock\" \n\t     app:drawableRightTintMode=\"src_in\"/\u003e\n    ```\n    \n    Here is the table that supporting attr of TintXXX widgets:\n    \n    | attr     | tint | tintMode   |\n    | :------- | ----: | :---: |\n    | background | backgroundTint |  backgroundTintMode    |\n    | src    | imageTint   |  imageTintMode   |\n    | button     | compoundButtonTint    |  compoundButtonTintMode  |\n    | drawableXxx     | drawableXxxTint    |  drawableXxxTintMode  |\n    | progress     | progressTint,progressIndeterminateTint    |    |\n    | track     | trackTint    |  trackTintMode  |\n    | thumb     | thumbTint    |  thumbTintMode  |\n\n  - Java code\n    TintXXX widgets can also be tinted in java code. The way of tinting drawable is the same as android native methods.\n    \n    Here is an example:\n\n    ```java\n    //the background of tintTextView is a shape selector, we can call method setBackgroundResource to tint the shape.\n    tintTextView.setBackgroundResource(R.drawable.selector_shape_lock);\n    \n    //the src of tintImageView is a selector containing the png，we need call method setImageTintList than the android native method call once more.\n    tintImageView.setImageResource(R.drawable.selecor_png_lock);\n    tintImageView.setImageTintList(R.color.selector_color_lock);\n    ```\n    \n- **STEP4** :\n  \n    The library provides utility class ThemeUtils to meet some special needs or your own custom widgets.\n    \n    Utility class ThemeUtils mainly provides the method of tinting drawable and convert the color variates(defining in Step 1) with the current theme including colorStateList and color.\n    \n    ```java\n    // R.color.selector_color.lock is a colorStateList, the method of ThemeUtils.getThemeColorStateList return the colorStateList with the current theme.\n    ThemeUtils.getThemeColorStateList(context, R.color.selector_color.lock);\n    ThemeUtils.getThemeColorStateList(context, context.getResource().getColorStateList(R.color.selector_color.lock));\n    ```\n- **STEP5** :\n  \n  About to support the night theme, there are two ways to choose.\n  \n  - Build night resource directories whitch are corresponding the default resource directories and put the independent night xml into corresponding directories, such as values-night/values, color-night/night ...\n  \n  - Define a series of color variates both in values-night/values which are same name but different value, then you just write a xml once with using the colors variates to adapt the night theme.\n    \n  ```java\n  // in value/color.xml\n  \u003ccolor name=\"theme_color_primary\"\u003e#2EA200\u003c/color\u003e\n  \u003ccolor name=\"theme_color_primary_dark\"\u003e#057748\u003c/color\u003e\n  \u003ccolor name=\"theme_color_primary_trans\"\u003e#992EA200\u003c/color\u003e\n  \u003ccolor name=\"theme_color_secondary\"\u003e#2EA200\u003c/color\u003e // special used for night theme primary color\n\n  // in values-night/color.xml\n  \u003ccolor name=\"theme_color_primary\"\u003e#2d2d2d\u003c/color\u003e\n  \u003ccolor name=\"theme_color_primary_dark\"\u003e#242424\u003c/color\u003e\n  \u003ccolor name=\"theme_color_primary_trans\"\u003e#992d2d2d\u003c/color\u003e\n  \u003ccolor name=\"theme_color_secondary\"\u003e#057748\u003c/color\u003e // special used for night theme primary color\n  ```\n   \n- **STEP6** :\n  \n  About to switch daily colorful theme, you can directly call the method Theme.refreshUI in main thread and this method also provides optional callback params to meet your custom needs during switching theme. \n  \n  About to switch night theme, when the version of your android support library is below 23.2.0, you can call the method of ThemeUtils.updateNightMode to switch in the night and daily theme, and when the version is above 23.2.0, you can use android native method in android support library.\n\n## Download\n[Demo Download here](http://7xr9x5.com1.z0.glb.clouddn.com/magicasrkura_sample-release.apk)\n\n## TODO\n- Refactor part of the code including TintManager...\n\n## License\n\nCopyright 2016 Bilibili\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbilibili%2Fmagicasakura","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbilibili%2Fmagicasakura","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbilibili%2Fmagicasakura/lists"}