Giter Site home page Giter Site logo

bilibili / magicasakura Goto Github PK

View Code? Open in Web Editor NEW
3.5K 3.5K 469.0 2.97 MB

MagicaSakura 是 Android 多主题框架。~ is an Android multi theme library which supporting both daily colorful theme and night theme.

Home Page: http://app.bilibili.com

License: Apache License 2.0

Java 100.00%
android-library colorful multi-theme multicolor svg theme vector

magicasakura's Introduction

cover

MagicaSakura

Download

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. Support Vector Drawable with appcompat-v7.
  1. Easy to integrate to your app.

Demo

ScreenShot.gif

You can download the lastest sample apk from Google Play.

Gradle Dependency

compile 'com.bilibili:magicasakura:0.1.9-beta3@aar'

Maven Dependency

<dependency>
  <groupId>com.bilibili</groupId>
  <artifactId>magicasakura</artifactId>
  <version>0.1.9-beta3</version>
  <type>aar</type>
</dependency>

Usage

  • STEP1 :

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.

  • STEP2 :

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;
       }
       ...
     }
}
  • STEP3 :

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.

  • Drawable Xml TintXXX widgets support common drawable xml tag, such as , , , , and etc in drawable xml.

    (Note: when using not supporting drawable xml tag, just can't be adapted to multi theme)

    Specially, TintXXX widgets additional support directly tint drawable with app:drawableTint and app:drawableTintMode and set color alpha with android:alpha.

    Here is an example:

    //drawable xml
    //tint directly
    <selector
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">
      <item android:drawable="@drawable/icon " android:state_pressed="true" app:drawableTint="@color/theme_color_primary" />
      <item android:drawable="@drawable/icon" app:drawableTint="@color/gray_dark" />
    </selector>
    // set color alpha in color
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="true" android:state_pressed="true">
            <shape>
              <corners android:radius="4dp" />
              <solid android:color="@color/theme_color_primary_dark" />
            </shape>
        </item>
        <item android:state_enabled="true">
            <shape>
              <solid android:color="@color/theme_color_primary" />
              <corners android:radius="4dp" />
            </shape>
        </item>
        <item android:state_enabled="false">
            <shape>
              <solid android:alpha="0.3" android:color="@color/theme_color_primary" />
              <corners android:radius="4dp" />
            </shape>
        </item>
    </selector>
  • Layout Xml TintXXX widgets can be tinted directly in layout xml that supporting most common android drawable attrs , such as background , src , drawableLeft, button and etc.

    (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)

    Here is an example:

    // shape_lock.xml
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <size android:width="1dp" />
        <solid android:color="@color/theme_color_primary" />
        <stroke android:color="@color/gray_dark" />
    </shape>
    
    // TintTextView
    // The selector_lock and selector_text is a ColorStateList
    // The shape_lock is a shape drawable.
    <com.bilibili.magicasakura.widgets.TintTextView
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:drawablePadding="@dimen/padding_half"
         android:drawableRight="@drawable/selector_lock"
         android:drwableLeft="@drawable/shape_lock"
         android:text="@string/textview_title"
         android:textColor="@color/selector_text"
         android:textSize="19sp" 
         app:drawableRightTint="@color/selector_lock" 
         app:drawableRightTintMode="src_in"/>

    Here is the table that supporting attr of TintXXX widgets:

    attr tint tintMode
    background backgroundTint backgroundTintMode
    src imageTint imageTintMode
    button compoundButtonTint compoundButtonTintMode
    drawableXxx drawableXxxTint drawableXxxTintMode
    progress progressTint,progressIndeterminateTint
    track trackTint trackTintMode
    thumb thumbTint thumbTintMode
  • Java code TintXXX widgets can also be tinted in java code. The way of tinting drawable is the same as android native methods.

    Here is an example:

    //the background of tintTextView is a shape selector, we can call method setBackgroundResource to tint the shape.
    tintTextView.setBackgroundResource(R.drawable.selector_shape_lock);
    
    //the src of tintImageView is a selector containing the png,we need call method setImageTintList than the android native method call once more.
    tintImageView.setImageResource(R.drawable.selecor_png_lock);
    tintImageView.setImageTintList(R.color.selector_color_lock);
  • STEP4 :

    The library provides utility class ThemeUtils to meet some special needs or your own custom widgets.

    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.

    // R.color.selector_color.lock is a colorStateList, the method of ThemeUtils.getThemeColorStateList return the colorStateList with the current theme.
    ThemeUtils.getThemeColorStateList(context, R.color.selector_color.lock);
    ThemeUtils.getThemeColorStateList(context, context.getResource().getColorStateList(R.color.selector_color.lock));
  • STEP5 :

    About to support the night theme, there are two ways to choose.

    • 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 ...

    • 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.

    // in value/color.xml
    <color name="theme_color_primary">#2EA200</color>
    <color name="theme_color_primary_dark">#057748</color>
    <color name="theme_color_primary_trans">#992EA200</color>
    <color name="theme_color_secondary">#2EA200</color> // special used for night theme primary color
    
    // in values-night/color.xml
    <color name="theme_color_primary">#2d2d2d</color>
    <color name="theme_color_primary_dark">#242424</color>
    <color name="theme_color_primary_trans">#992d2d2d</color>
    <color name="theme_color_secondary">#057748</color> // special used for night theme primary color
  • STEP6 :

    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.

    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.

Download

Demo Download here

TODO

  • Refactor part of the code including TintManager...

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.

magicasakura's People

Contributors

bryant1410 avatar jungerr avatar oceancx avatar xyczero avatar yrom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magicasakura's Issues

使用CoordinatorLayout,切换夜间模式后Glide加载的图片没有了

这是我的布局文件
如果直接设置本地图片不用Glide加载,切换后图片没有异常,但是用Glide加载,切换夜间模式后图片就没有了

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/iv_logo_past_week"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/x70"
            android:layout_marginRight="@dimen/x70"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="@dimen/x9"
            android:text="fdsafsdafassad"
            android:textColor="#aaa"
            android:textSize="@dimen/x13"/>

    </LinearLayout>

        <com.ajguan.library.EasyRefreshLayout
            android:id="@+id/refreshlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/pageBehavior">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </com.ajguan.library.EasyRefreshLayout>

</android.support.design.widget.CoordinatorLayout>

请教EditText中设置tintBackgroud的问题

EditText中设置tintBackgroud对默认背景无法生效,需要和官方demo一样自己设置图片背景才会生效。 看了源码,没找到其中为什么不生效。(tintBackgroud默认背景在普通状态下生效,在选中状态下不生效)

缺少 TintTabLayout

有 android:background app:tabSelectedTextColor app:tabTextColor 三个属性需要替换。
另外 loadFromAttribute 方法不是 public ,扩展很不方便(我现在是把用到的 helper 和 base 都复制了一遍),有什么特别用意吗?

TintAppBarLayout中嵌套CollapsingToolbarLayout和TintToolbar,折叠后toolbar颜色问题

布局文件如下:
问题:1,折叠后toolbar是透明的,颜色不知道怎么设置,demo也没有??
2,状态栏必须在每个activity的onpostcreat()方法中,设置状态栏么??
3,怎么设置默认值?能否在application中设置?

<com.bilibili.magicasakura.widgets.TintAppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/theme_color_primary"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/coll_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/detail_image_height"
        android:fitsSystemWindows="true"
        app:expandedTitleMarginEnd="96dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">


        <ImageView
            android:id="@+id/detail_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:background="@drawable/black_bg" />

        <com.bilibili.magicasakura.widgets.TintToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:backgroundTint="@color/theme_color_primary"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/tablayout_height"
        android:visibility="gone"
        app:tabIndicatorColor="@color/white"
        app:tabSelectedTextColor="@color/white"
        app:tabTextColor="@color/white" />
</com.bilibili.magicasakura.widgets.TintAppBarLayout>

<com.jude.easyrecyclerview.EasyRecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:scrollbarStyle="insideOverlay" />

<RelativeLayout
    android:id="@+id/rl_progress"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:visibility="visible">

    <ProgressBar
        android:id="@+id/pb_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <TextView
        android:id="@+id/tv_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:padding="@dimen/padding_16"
        android:text="@string/tryagain"
        android:textColor="@color/text_primary_color"
        android:textSize="@dimen/textsize_16" />
</RelativeLayout>

error inflating TintWidget when running Robolectric unit test

Caused by: java.lang.NullPointerException at org.robolectric.android.XmlResourceParserImpl.getResourceId(XmlResourceParserImpl.java:789) at org.robolectric.android.XmlResourceParserImpl.getAttributeNameResource(XmlResourceParserImpl.java:596) at org.robolectric.shadows.ShadowAssetManager.findAttributeValue(ShadowAssetManager.java:823) at org.robolectric.shadows.ShadowAssetManager.buildTypedValue(ShadowAssetManager.java:747) at org.robolectric.shadows.ShadowAssetManager.attrsToTypedArray(ShadowAssetManager.java:795) at org.robolectric.shadows.ShadowResourcesImpl$ShadowThemeImpl.obtainStyledAttributes(ShadowResourcesImpl.java:177) at android.content.res.ResourcesImpl$ThemeImpl.obtainStyledAttributes(ResourcesImpl.java) at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1493) at android.content.Context.obtainStyledAttributes(Context.java:599) at com.bilibili.magicasakura.utils.ColorStateListUtils.inflateColorStateList(ColorStateListUtils.java:110) at com.bilibili.magicasakura.utils.ColorStateListUtils.createFromXmlInner(ColorStateListUtils.java:92) at com.bilibili.magicasakura.utils.ColorStateListUtils.createColorStateList(ColorStateListUtils.java:72) at com.bilibili.magicasakura.utils.TintManager.getColorStateList(TintManager.java:115) at com.bilibili.magicasakura.utils.DrawableUtils.getTintColorList(DrawableUtils.java:173) at com.bilibili.magicasakura.utils.RippleDrawableInflateImpl.inflateDrawable(RippleDrawableInflateImpl.java:41) at com.bilibili.magicasakura.utils.DrawableUtils.createFromXmlInner(DrawableUtils.java:107) at com.bilibili.magicasakura.utils.DrawableUtils.createDrawable(DrawableUtils.java:75) at com.bilibili.magicasakura.utils.TintManager.getDrawable(TintManager.java:146) at com.bilibili.magicasakura.widgets.AppCompatBackgroundHelper.loadFromAttribute(AppCompatBackgroundHelper.java:69) at com.bilibili.magicasakura.widgets.TintButton.<init>(TintButton.java:56) at com.bilibili.magicasakura.widgets.TintButton.<init>(TintButton.java:45) at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994) at android.view.LayoutInflater.rInflate(LayoutInflater.java:854) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:426) at android.view.LayoutInflater.inflate(LayoutInflater.java:377) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) at com.ladddd.myandroidarch.ui.activity.MainActivity.initView(MainActivity.java:98)

请问我如果使用google原生的BottomNavigationView来当做底部的导航,可以让导航栏选中切换成当前的主题色吗?

下面是我的布局代码,也就是谷歌原生的底部导航

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/window_background"
    tools:context=".ui.main.MainActivity">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:elevation="5dp"
        app:itemTextColor="@color/color_navigation_view"
        app:itemIconTint="@color/color_navigation_view"
        app:menu="@menu/navigation"/>

    <android.support.v4.view.ViewPager
        android:visibility="visible"
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/navigation"
        android:overScrollMode="never">
    </android.support.v4.view.ViewPager>

</RelativeLayout>

在vivo x5xl机型上报错

app已经上线了,只有在这个机型会报错,不知道什么原因。

android.view.InflateException: Binary XML file line #32: Error inflating class com.bilibili.magicasakura.widgets.TintRadioButton
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at cn.geekdream.jhglsy.fragments.BaseFragment.onCreateView(BaseFragment.java)
at android.support.v4.app.Fragment.performCreateView(Fragment.java)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java)
at android.support.v4.view.ViewPager.populate(ViewPager.java)
at android.support.v4.view.ViewPager.populate(ViewPager.java)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2391)
at android.view.View.measure(View.java:16926)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2469)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1385)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1655)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1262)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6456)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5351)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 62 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1159)
at android.content.res.VivoResources.getValue(VivoResources.java:175)
at android.content.res.Resources.getColor(Resources.java:831)
at cn.geekdream.jhglsy.JhglsyApplication.replaceColor(JhglsyApplication.java)
at com.bilibili.magicasakura.utils.ThemeUtils.replaceColor(ThemeUtils.java)
at com.bilibili.magicasakura.utils.DrawableUtils.getAttrColor(DrawableUtils.java)
at com.bilibili.magicasakura.utils.DrawableUtils.getAttrColorFilter(DrawableUtils.java)
at com.bilibili.magicasakura.utils.StateListDrawableInflateImpl.inflateDrawable(StateListDrawableInflateImpl.java)
at com.bilibili.magicasakura.utils.DrawableUtils.createFromXmlInner(DrawableUtils.java)
at com.bilibili.magicasakura.utils.DrawableUtils.createDrawable(DrawableUtils.java)
at com.bilibili.magicasakura.utils.TintManager.getDrawable(TintManager.java)
at com.bilibili.magicasakura.widgets.AppCompatCompoundButtonHelper.loadFromAttribute(AppCompatCompoundButtonHelper.java)
at com.bilibili.magicasakura.widgets.TintRadioButton.(TintRadioButton.java)
at com.bilibili.magicasakura.widgets.TintRadioButton.(TintRadioButton.java)
... 65 more
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at cn.geekdream.jhglsy.fragments.BaseFragment.onCreateView(BaseFragment.java)
at android.support.v4.app.Fragment.performCreateView(Fragment.java)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java)
at android.support.v4.view.ViewPager.populate(ViewPager.java)
at android.support.v4.view.ViewPager.populate(ViewPager.java)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
at android.view.View.measure(View.java:16926)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5411)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2391)
at android.view.View.measure(View.java:16926)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2469)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1385)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1655)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1262)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6456)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)

自定义Tintable控件issue

作者您好,在下准备写一个继承TabLayout并且实现Tintable接口时发现,AppCompatBackgroundHelper的loadFromAttribute不是public,希望作者能放开这个方法好让群众更加方便的去实现自己的Tintable控件,
阿里嘎多

TintProgressBar不变色,其余组件变色正常

下面是我的布局代码,机型是mi6 android版本是7.1
`
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/playbar_img"
android:layout_width="43dp"
android:layout_height="43dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_weight="0"
fresco:layout_constraintBottom_toTopOf="@+id/guideline"
fresco:layout_constraintLeft_toLeftOf="parent"
fresco:placeholderImage="@mipmap/placeholder_disk_210"
fresco:placeholderImageScaleType="fitXY"/>


<com.bilibili.magicasakura.widgets.TintImageView
android:id="@+id/play_list"
android:layout_width="43dp"
android:layout_height="43dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:onClick="click_last"
android:src="@mipmap/playbar_btn_playlist"
fresco:imageTint="@color/theme_color_primary"
fresco:layout_constraintBottom_toTopOf="@+id/guideline"
fresco:layout_constraintRight_toLeftOf="@+id/control"/>

<com.bilibili.magicasakura.widgets.TintImageView
    android:id="@+id/control"
    android:layout_width="41dp"
    android:layout_height="46dp"
    android:layout_marginBottom="16dp"
    android:layout_marginEnd="4dp"

    android:layout_marginRight="4dp"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:src="@mipmap/playbar_btn_play"
    fresco:imageTint="@color/theme_color_primary"
    fresco:layout_constraintBottom_toTopOf="@+id/guideline"
    fresco:layout_constraintRight_toLeftOf="@+id/play_next"/>

<com.bilibili.magicasakura.widgets.TintImageView
    android:id="@+id/play_next"
    android:layout_width="43dp"
    android:layout_height="43dp"
    android:layout_marginBottom="16dp"
    android:layout_marginEnd="4dp"
    android:layout_marginRight="4dp"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:onClick="click_next"
    android:src="@mipmap/playbar_btn_next"
    fresco:imageTint="@color/theme_color_primary"
    fresco:layout_constraintBottom_toTopOf="@+id/guideline"
    fresco:layout_constraintRight_toRightOf="parent"/>
<android.support.constraint.Guideline android:id="@+id/guideline"
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:orientation="horizontal"
                                      fresco:layout_constraintGuide_begin="60dp"
/>
<com.bilibili.magicasakura.widgets.TintProgressBar
    android:id="@+id/song_progress_normal"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    android:layout_width="0dp"
    android:layout_height="10dp"
    android:layout_marginBottom="5dp"
    android:progress="0"
    android:max="100"
    app:layout_constraintBottom_toTopOf="@+id/guideline"
    app:layout_constraintHorizontal_bias="0.533"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:progressIndeterminateTint="@color/theme_color_primary"/>

</android.support.constraint.ConstraintLayout>`

这是我的项目地址:https://github.com/NightXlt/NetEaseMusic

release版本编译阶段报错

1、Warning:com.bilibili.magicasakura.widgets.TintGridLayout: can't find referenced method 'boolean isInEditMode()' in program class com.bilibili.magicasakura.widgets.TintGridLayout
已查到原因,建议增加混淆规则
2、希望能增加Switch控件支持

夜间模式

您好,请问能不能补充说明一下夜间模式的使用步骤啊,或者在demo中加个夜间模式的例子,看了好几天还是没明白用您的这个library怎么处理一个模式设置不同控件变成不同颜色。

切换主题后的一些问题

  1. 八种颜色,第一种粉色,点击切换后没反应。其他的颜色切换都可以。
  2. 切换了主题后 状态栏变色,但是进入下一个页面,状态栏又回到了原来的颜色。但是标题栏和控件是改变了的

我在基类的Activity里设置的监听切换,所有上下文都是同一个。

tintimageview 图片切换

@ColorRes
int getThemeColorId(Context context, int colorId, String theme) {
    switch (colorId) {
        case R.color.theme_color_primary:
            return context.getResources().getIdentifier(theme, "color", getPackageName());
        case R.color.theme_color_primary_dark:
            return context.getResources().getIdentifier(theme + "_dark", "color", getPackageName());
        case R.color.theme_color_primary_trans:
            return context.getResources().getIdentifier(theme + "_trans", "color", getPackageName());
    }
    return colorId;
}

private
@ColorRes
int getThemeColor(Context context, int color, String theme) {
    switch (color) {
        case 0xfffb7299:
            return context.getResources().getIdentifier(theme, "color", getPackageName());
        case 0xffb85671:
            return context.getResources().getIdentifier(theme + "_dark", "color", getPackageName());
        case 0x99f0486c:
            return context.getResources().getIdentifier(theme + "_trans", "color", getPackageName());
        case R.drawable.yellow_one:
            return context.getResources().getIdentifier(theme + "_one", "drawable", getPackageName());
        case R.drawable.red_two:
            return context.getResources().getIdentifier(theme + "_two", "drawable", getPackageName());
    }
    return -1;
}











        case R.drawable.yellow_one:
            return context.getResources().getIdentifier(theme + "_one", "drawable", getPackageName());
        case R.drawable.red_two:
            return context.getResources().getIdentifier(theme + "_two", "drawable", getPackageName());
    使用不行?

在ListView上面使用出现item混乱

使用ListView的话,如果滑动到一定距离,有些item被复用的话,切换Theme,这时候ListView当前页面的item成功换色,但是再次滑动会出现被复用的换色前的item,请问这个问题如何解决的?

gradle 无法同步

Error:(2, 0) No service of type Factory available in ProjectScopeServices.

好像是这个 依赖打不开
apply plugin: 'com.github.dcendents.android-maven'

File877b48d4afc0.png)

一个很奇怪的问题

<com.bilibili.magicasakura.widgets.TintTextView
    android:id="@+id/tv_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="?attr/eStatusTextSize"
    android:textColor="@color/emotion_item_tv_color_selector"/>

当textColor 设置为一个selector 然后 textSize设置主题里面的字体大小
在AppCompatCompoundDrawableHelper.loadFromAttribute 出现异常:
android.content.res.Resources$NotFoundException:Resource "com.caij.emore:dimen/status_text_size_16" (7f0900b0) is not a Drawable (color or path): TypedValue{t=0x5/d=0xf01 a=5 r=0x7f0900b0}

但是不是必现的。

v4 包更新版本有错误

compile "com.android.support:appcompat-v7:${rootProject.ext.supportVersion}" compile "com.android.support:design:${rootProject.ext.supportVersion}" compile "com.android.support:gridlayout-v7:${rootProject.ext.supportVersion}"
在demo里面 ,把rootProject.ext.supportVersion 有25.3.1 升级到27.1.0 的时候ThemeUtils ``的getWrapperDrawable方法报错。
public static Drawable getWrapperDrawable(Drawable drawable) { if (drawable instanceof android.support.v4.graphics.drawable.DrawableWrapper) { return ((android.support.v4.graphics.drawable.DrawableWrapper) drawable).getWrappedDrawable(); } else if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) { return ((android.support.v7.graphics.drawable.DrawableWrapper) drawable).getWrappedDrawable(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && drawable instanceof android.graphics.drawable.DrawableWrapper) { return ((android.graphics.drawable.DrawableWrapper) drawable).getDrawable(); } return drawable; } v4下的DrawableWrapper找不到。是升级版本的原因吗?

夜间模式

您好,请问哔哩哔哩动画中的夜间模式是怎么实现的?我在demo里做了修改,但是只是改变了toolbar、文字等控件的颜色,界面的背景色还是白色的。

关于ProgressBar的问题

AppCompatProgressBarHelper.loadFromAttribute(){
TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
if (array.hasValue(0)) {
mProgressTintResId = array.getResourceId(0, 0);
setSupportProgressTint(array.getColorStateList(0));
}
if (array.hasValue(1)) {
mIndeterminateTintResId = array.getResourceId(1, 0);
setSupportIndeterminateTint(array.getColorStateList(1));
}
array.recycle();
}

改成下面
AppCompatProgressBarHelper.loadFromAttribute(){
TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
if (array.hasValue(0)) {
mProgressTintResId = array.getResourceId(0, 0);
setSupportProgressTint(hemeUtil.getThemeColorStateList(mProgressTintResId));
}
if (array.hasValue(1)) {
mIndeterminateTintResId = array.getResourceId(1, 0);
setSupportIndeterminateTint(ThemeUtil.getThemeColorStateList(mIndeterminateTintResId));
}
array.recycle();
}

这样可以避免replaceColor这个方法里面替换颜色 感觉这个方法太不可靠了, 只需要replaceColorById 这个里面替换颜色id就行, id替换感觉更加可靠。

请问TintEditText光标颜色要如何适配

demo中edittext_cursor.xml修改为

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:width="1dp" />
    <solid android:color="@color/theme_color_primary_trans" />
</shape>

光标颜色并不会变化

TintProgressBar不显示

我在新建的App里使用TintProgressBar时设置了app:progressIndeterminateTint="@color/theme_color_primary"
时就显示不出来这个TintProgressBar了,不设置这个属性的时候才可以显示。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.