【问题标题】:Set vector drawable programmatically pre Lollipop在 Lollipop 之前以编程方式设置矢量可绘制对象
【发布时间】:2017-09-12 02:00:58
【问题描述】:

一个非常常见的问题,我找不到解决方案。 我正在以编程方式设置我的向量。我也希望能够以编程方式更改色调颜色。 找到了一些解决方案,例如 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 只接受设置视图的可绘制对象

iv.setImageResource(int resource)

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

【问题讨论】:

    标签: android vector drawable android-resources


    【解决方案1】:

    使用具有setImageDrawable() 方法的 AppCompatImageView。

    【讨论】:

    • 实际上问题在于正确设置drawable。如果使用 Drawable vectorIcon = VectorDrawableCompat.create(view.getResources(), vectorDrawableSource, themeSource);它工作得很好!谢谢!
    猜你喜欢
    • 2018-03-23
    • 2019-08-14
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    相关资源
    最近更新 更多