简体   繁体   English

将可绘制的预棒棒糖着色

[英]Tint a drawable pre Lollipop

So i'm trying to tint some Drawable at runtime, to achieve this i'm using a custom Resources class to return the Drawable tinted. 因此,我试图在运行时着色一些Drawable,以实现此目的,我正在使用自定义Resources类返回Drawable着色。

Something like: 就像是:

public final class MyResources extends Resources
{
    public Drawable getDrawable(int resId) throws NotFoundException {
        Drawable drawable = super.getDrawable(resId);
        drawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
        return drawable;
    }
}

When the drawable is set to the widget, In some widgets like EditText, Buttons the drawable is mutated and the filter is lost. 当将drawable设置为窗口小部件时,在某些窗口小部件(如EditText,Buttons)中,drawable会发生突变,并且过滤器也会丢失。

The real code is at: https://github.com/SiegenthalerSolutions/QuantumPaper/blob/master/library/src/main/java/me/siegenthaler/quantum_paper/QuantumResources.java 真正的代码位于: https : //github.com/SiegenthalerSolutions/QuantumPaper/blob/master/library/src/main/java/me/siegenthaler/quantum_paper/QuantumResources.java

And what i want is to prevent setting the drawable for the second time: (Hackish) 我想要的是防止第二次设置可绘制对象:(笑)

https://github.com/SiegenthalerSolutions/QuantumPaper/blob/master/library/src/main/java/me/siegenthaler/quantum_paper/interceptor/SimpleBackgroundInterceptor.java https://github.com/SiegenthalerSolutions/QuantumPaper/blob/master/library/src/main/java/me/siegenthaler/quantum_paper/interceptor/SimpleBackgroundInterceptor.java

Try my library. 试试我的图书馆。 I implemented a special drawable to tint drawables for custom EditText. 我实现了一个特殊的可绘制对象,以为自定义EditText着色可绘制对象。 This should work for all other cases too. 这同样适用于所有其他情况。

https://github.com/rekire/TintedDrawable https://github.com/rekire/TintedDrawable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM