【问题标题】:How to use SVG icons with linearGradient in android如何在android中使用带有linearGradient的SVG图标
【发布时间】:2017-12-28 20:30:55
【问题描述】:

我的设计师给了我一些 SVG 格式的图标。我正在尝试将它们添加到我的应用程序中。

我注意到 svg 中有 <lineargradient> 标签。

我通过 AndroidStudio -> File -> New -> Vector Assets 导入了这些 svgs

一旦我使用这些 svgs 启动我的应用程序。

任何包含使用这些 SVG 的 ImageView 的屏幕都会立即使我的应用程序崩溃。在 API-23 上

我在这里有一个示例应用程序

https://github.com/liuzhen2008/whydoesntthiswork

让我感到困惑的是,我可以在构建生成的文件夹中看到,创建了许多不同大小的 PNG。

为什么我的应用会崩溃?我以为他们只是使用这些生成的 PNG。

我有什么选择? Android Studio 中是否有其他工具可以让我快速将这些 svg 转换为 PNG 并直接使用它们?

【问题讨论】:

    标签: android svg


    【解决方案1】:

    根据我的建议,尝试使用 app:srcCompat="@drawable/ic_baloons" 而不是 android:src="@drawable/ic_baloons"。

    这是你的代码:

    <ImageView
    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_baloons" />
    

    您的代码更改:

    <ImageView
    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_baloons"  />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2019-08-07
      • 2012-04-30
      • 2021-06-20
      • 2020-03-16
      • 2021-04-02
      相关资源
      最近更新 更多