【问题标题】:Changing the background of vector drawable programatically以编程方式更改矢量绘图的背景
【发布时间】:2018-08-10 07:09:08
【问题描述】:
    <?xml version="1.0" encoding="utf-8"?>
<vector android:height="24dp"
    android:viewportHeight="628.0"
    android:viewportWidth="726.0"
    android:width="27dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <path
        android:fillColor="#00ffffff"
        android:pathData="m723,314c-60,103.9 -120,207.8 -180,311.8 -120,0 -240,0 -360,0C123,521.8 63,417.9 3,314 63,210.1 123,106.2 183,2.2c120,0 240,0 360,0C603,106.2 663,210.1 723,314Z"
        android:strokeColor="#000000"
        android:strokeWidth="4"/>
</vector>

我想在运行时更改 fillColor 部分,以便我可以重复使用此形状以供多次使用。

【问题讨论】:

标签: android android-drawable android-vectordrawable


【解决方案1】:

你必须这样尝试

DrawableCompat.setTint(myImageView.getDrawable(), ContextCompat.getColor(context, R.color.new_color));

注意:myImageView您的图像视图对象

【讨论】:

  • 它改变图像的颜色而不是矢量的颜色
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多