• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

TintImage: 仿IOS版QQ音乐自定义主题色的android版demo

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

TintImage

开源软件地址:

https://gitee.com/androidzk/TintImage

开源软件介绍:

#效果图

输入图片说明输入图片说明

#核心代码

/**     * 实现ImageView的变色     *     * @param imageView     * @param color     */    public static void setTint(@NonNull ImageView imageView, @ColorInt int color) {        ColorStateList s1 = ColorStateList.valueOf(color);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            imageView.setImageTintList(s1);        } else {            PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {                mode = PorterDuff.Mode.MULTIPLY;            }            if (imageView.getDrawable() != null)                imageView.getDrawable().setColorFilter(color, mode);        }    }
/**     * 实现textView的Compound图标变色     *     * @param textView     * @param color     * @param isChangeTextColor 是否改变字的颜色     */    public static void setCompoundTint(@NonNull TextView textView, @ColorInt int color, boolean isChangeTextColor) {        ColorStateList s1 = ColorStateList.valueOf(color);        if (isChangeTextColor) {            textView.setTextColor(s1);        }        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {            textView.setCompoundDrawableTintList(s1);        } else {            PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {                mode = PorterDuff.Mode.MULTIPLY;            }            for (Drawable d : textView.getCompoundDrawables()) {                if (d != null)                    d.setColorFilter(color, mode);            }        }    }
/**     * @param button     * @param color     */    public static void setTint(@NonNull Button button, @ColorInt int color) {        ColorStateList s1 = ColorStateList.valueOf(color);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {            button.setBackgroundTintList(s1);        } else {            PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {                mode = PorterDuff.Mode.MULTIPLY;            }            if (button.getBackground() != null)                button.getBackground().setColorFilter(color, mode);        }    }
/**     * 处理SeekBar的变色     *     * @param seekBar     * @param color     */    public static void setTint(@NonNull SeekBar seekBar, @ColorInt int color) {        ColorStateList s1 = ColorStateList.valueOf(color);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            seekBar.setThumbTintList(s1);            seekBar.setProgressTintList(s1);        } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {            Drawable progressDrawable = DrawableCompat.wrap(seekBar.getProgressDrawable());            seekBar.setProgressDrawable(progressDrawable);            DrawableCompat.setTintList(progressDrawable, s1);            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {                Drawable thumbDrawable = DrawableCompat.wrap(seekBar.getThumb());                DrawableCompat.setTintList(thumbDrawable, s1);                seekBar.setThumb(thumbDrawable);            }        } else {            PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {                mode = PorterDuff.Mode.MULTIPLY;            }            if (seekBar.getIndeterminateDrawable() != null)                seekBar.getIndeterminateDrawable().setColorFilter(color, mode);            if (seekBar.getProgressDrawable() != null)                seekBar.getProgressDrawable().setColorFilter(color, mode);        }    }

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap