Home

Awesome

cover

MagicaSakura

MagicaSakura is an Android multi theme library which supporting both daily colorful theme and night theme.

##Feature

  1. Support both the daily colorful theme and the night theme.
  1. Switch different theme without recreating activities.
  1. Provide TintXXX Widgets for adapting multi theme to be more convenient and fast.
  1. Just writie a drawable.xml or layout.xml can be automatically adapted to different theme styles.
  1. Offer backward-compatible versions of the Android system that can be used with 4.0.3 or higher.
  1. Easy to integrate to your app.

##Demo

ScreenShot.gif

##Gradle Dependency

compile 'com.bilibili:magicasakura:0.1.1@aar'

##Maven Dependency

<dependency>
  <groupId>com.bilibili</groupId>
  <artifactId>magicasakura</artifactId>
  <version>0.1.1</version>
  <type>aar</type>
</dependency>

##Usage

Define your app global theme color variates in values/color.xml, like as:

<color name="theme_color_primary">#fb7299</color>
<color name="theme_color_primary_dark">#b85671</color>
<color name="theme_color_primary_trans">#99f0486c</color>

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. If you use direct color value or other color variates, adapting different theme styles will be out of work.

Implement ThemeUtils.switchColor interface in the app Applaction; You Define your own rules combining with the color variates(defining in Step 1) for switching different colors when choosing different themes.

public class MyApplication extends Application implements ThemeUtils.switchColor {
     @Override
     public void onCreate() {
         super.onCreate();
         //init
         ThemeUtils.setSwitchColor(this);
     }
     
     @Override
     public int replaceColorById(Context context, @ColorRes int colorId) {
       ...
       if(ThemeHelper.getThemeId(context) == "blue"){
           switch (colorId) {
             // define in Step 1
             case R.color.theme_color_primary:
               return R.color.blue;
               ...
           }
       ...
     }

     @Override
     public int replaceColor(Context context, @ColorInt int originColor) {
       if (ThemeHelper.isDefaultTheme(context)) {
           return originColor;
       }
       ...
     }
}

The library provides a series of TintXXX widgets which including most common android widgets.

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.

##Download Demo Download here

##License

Copyright 2016 Bilibili

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.