不支持低于API 24的渐变颜色的矢量可绘制图形。
创始人
2025-01-11 22:00:17
0

要解决这个问题,你可以使用 AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) 方法来启用矢量可绘制图形的支持。这样,你就可以在低于 API 24 的设备上使用渐变颜色。

以下是一个代码示例:

import android.app.Application;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.VectorDrawable;

import androidx.appcompat.app.AppCompatDelegate;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // 启用矢量可绘制图形的支持
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

        // 创建一个渐变颜色的矢量可绘制图形
        Drawable drawable = getResources().getDrawable(R.drawable.gradient_drawable);

        // 检查矢量可绘制图形的类型并处理渐变颜色
        if (drawable instanceof GradientDrawable) {
            GradientDrawable gradientDrawable = (GradientDrawable) drawable;
            // 设置渐变颜色
            gradientDrawable.setColors(new int[]{0xFF000000, 0xFFFFFFFF});
        } else if (drawable instanceof VectorDrawable) {
            // 在这里处理 VectorDrawable 的渐变颜色,例如使用 XML 来定义渐变
        }
    }
}

在这个示例中,我们首先通过调用 AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) 来启用矢量可绘制图形的支持。然后,我们通过 getResources().getDrawable(R.drawable.gradient_drawable) 获取一个渐变颜色的矢量可绘制图形。最后,我们检查矢量可绘制图形的类型,并根据需要处理渐变颜色。

请注意,如果你在使用 VectorDrawableCompat 或是其他库来处理矢量可绘制图形,你可能需要根据库的要求进行相应的设置。

相关内容

热门资讯

透视神器!pokemmo手机版... 透视神器!pokemmo手机版修改器,淘宝的微乐辅助是真的吗,解密脚本(有挂猫腻)-哔哩哔哩在进入p...
脚本解迷!德扑HHpoker有... 脚本解迷!德扑HHpoker有挂吗,hhpoker免费辅助器(透视)竟然是有攻略(哔哩哔哩)1)辅助...
透视透视挂!we poker游... 透视透视挂!we poker游戏下,微乐家乡小程序辅助,关于脚本(有人有挂)-哔哩哔哩we poke...
脚本曝光!wepoker透视底... 脚本曝光!wepoker透视底牌脚本,wejoker开挂(透视)都是真的是有插件(哔哩哔哩)1、玩家...
更值得关注的是!wepoker... 您好,wepoker透视脚本网页这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
脚本有挂!wepoker破解是... 脚本有挂!wepoker破解是真的还是假的,wepoker破解器(透视)竟然是有器(哔哩哔哩)1、模...
透视有挂!pokemmo辅助脚... 透视有挂!pokemmo辅助脚本,微信小程序微乐房间的挂多少钱,详情透视(有挂辅助)-哔哩哔哩pok...
透视必备!wepoker透视底... 透视必备!wepoker透视底牌脚本,wepoker私人辅助器(透视)其实存在有器(哔哩哔哩)1、许...
今年以来!大菠萝免费辅助器,微... 今年以来!大菠萝免费辅助器,微信小程序微乐辅助器,科普脚本(有挂功能)-哔哩哔哩大菠萝免费辅助器透视...
透视安装!newpoker脚本... 透视安装!newpoker脚本,手机微乐小程序游戏破解器,分享透视(有挂猫腻)-哔哩哔哩newpok...