不支持低于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 或是其他库来处理矢量可绘制图形,你可能需要根据库的要求进行相应的设置。

相关内容

热门资讯

透视挂透视!aapoker a... 透视挂透视!aapoker ai插件(透视)辅助(真是有挂);1、首先打开aapoker ai插件最...
透视辅助!wepoker私人局... 透视辅助!wepoker私人局俱乐部辅助,wepoker私人局可以透视(详细内置辅助)1、完成wep...
透视模拟器!aapoker辅助... 透视模拟器!aapoker辅助软件合法吗(透视)透视脚本下载(确实存在有挂)1、这是跨平台的aapo...
透视智能ai!we-poker... 透视智能ai!we-poker软件,wepoker透视底牌脚本(详细永久免费脚本);1、许多玩家不知...
透视线上!aapoker发牌逻... 透视线上!aapoker发牌逻辑(透视)透视插件(一直是有挂)1、完成aapoker发牌逻辑透视辅助...
透视辅助!wepoker轻量版... 透视辅助!wepoker轻量版透视系统,wepoker私局代打(详细黑侠辅助器)1)wepoker轻...
透视安卓版!aapoker透视... 透视安卓版!aapoker透视方法(透视)插件下载(本来是有挂)1、不需要AI权限,帮助你快速的进行...
透视有挂!有没有人wepoke... 透视有挂!有没有人wepoker,wepoker私人辅助器(详细透视最简单三个步骤)1、wepoke...
透视中牌率!wepokerpl... 透视中牌率!wepokerplus到底是挂了吗,wepoker轻量版透视(详细有脚本)1、进入游戏-...
透视讲解!aapoker怎么控... 透视讲解!aapoker怎么控制牌(透视)ai插件(果然是有挂)aapoker怎么控制牌辅助器中分为...