以编程方式设置可绘制的矢量棒棒糖之前 [英] Set vector drawable programmatically pre Lollipop

查看:91
本文介绍了以编程方式设置可绘制的矢量棒棒糖之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个非常常见的问题,我无法解决.我正在以编程方式设置向量.我也希望能够以编程方式更改色调颜色.找到了一些解决方案,例如以编程方式为支持向量着色

Very common problem with a twist to which I couldn't find a solution for. I am setting my vector programmatically. I want to be able to change the tint color programmatically too. Found some solutions such as Programmatically tint a Support Vector

ImageView iv = ....
Drawable d = VectorDrawableCompat.create(getResources(), R.drawable.ic_exit_to_app_24dp, null);
d = DrawableCompat.wrap(d);
DrawableCompat.setTint(d, headerTitleColor);
iv.setImageDrawable(d);

主要问题来自

iv.setImageDrawable(d);

我发现prelolipop仅接受设置视图的可绘制对象,

I found that prelolipop only accepts setting view's drawable with

iv.setImageResource(int resource)

我找不到用可绘制文件设置它的任何解决方案.

I couldn't find any solutions for setting it with a drawable file.

推荐答案

使用具有 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆