如何申请一个彩色滤光片与所有儿童期 [英] How to apply a color filter to a view with all children
问题描述
我如何灰了看法一致,其中包含许多不同的项目 - ImageViews,TextViews,背景图像。我一定要单独变灰每一件事情?还是有办法适用相同的颜色过滤器将所有?
How do I grey out a view uniformly which contains many different items - ImageViews, TextViews, background image. Do I have to grey out each thing individually? Or is there a way to apply the same color filter to all?
推荐答案
除非别人有更好的答案,我现在的方法separatedly花白的每一项。
Unless somebody else has a better answer, my current method is greying out each item separatedly.
PorterDuffColorFilter greyFilter = new PorterDuffColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
myLayout.getBackground().setColorFilter(greyFilter);
myImageView.setColorFilter(greyFilter);
myTextView.setTextColor(0xff777777);
有关更多的或嵌套的孩子可能与的instanceof循环将是合适的,但我并不需要它。
For more or nested children probably a loop with instanceof would be suitable but I don't need it.
编辑:此过滤器实际上不是灰色的,更好的过滤器是在这里:绘制对象=>灰度 这可以在相同的方式使用。
This filter isn't actually grey, a better filter is here: Drawable => grayscale Which can be used in the same way.
这篇关于如何申请一个彩色滤光片与所有儿童期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!