You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

API 24以下版本ImageView中带渐变的Vector Drawable不显示问题求助(Android Studio 3.1)

Fix for Gradient Vector Drawables Not Showing on API <24 in ImageView

Hey there! I’ve dealt with this exact headache when supporting older Android devices, so let me share the solutions that got my gradient vectors working properly:

1. Use AppCompatImageView Instead of Regular ImageView

Older Android versions don’t handle gradient vectors well with the standard ImageView. Switch to AppCompatImageView from the support library—it’s built to handle vector drawables (including gradients) for API levels down to 14.

In your layout XML, replace:

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

With:

<androidx.appcompat.widget.AppCompatImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/your_gradient_vector" />

Note: Make sure to use app:srcCompat instead of android:src to leverage the support library’s vector handling.

2. Enable Vector Drawable Support in Build.Gradle

Double-check your app-level build.gradle to ensure you’ve enabled support library integration for vector drawables:

For Groovy:

android {
    defaultConfig {
        // Add this line to enable vector support
        vectorDrawables.useSupportLibrary = true
    }
}

dependencies {
    // Keep the AppCompat dependency (adjust version to match your Android Studio 3.1 setup)
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

3. Fallback to PNGs for Stubborn Gradients (If Needed)

If the above fixes still don’t work for super complex gradients, create a PNG version of your vector drawable and place it in the drawable-nodpi directory. Keep the original vector in drawable-v24—this way, API 24+ devices use the scalable vector, and older devices fall back to the reliable PNG. Just make sure both files have the exact same name so the system picks the right one automatically.


内容的提问来源于stack exchange,提问作者Merve Genç

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 08:12:34