当前位置: 首页 > 知识库问答 >
问题:

Android向量支持错误

乔凯康
2023-03-14

我的应用程序在5.1.0中运行平稳,但当我在4.2.2中运行时,它显示错误:

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector 

我研究过这个。它说在gradle中添加向量支持错误,所以我补充道:

compileSdkVersion 23
buildToolsVersion "25.0.1"
 defaultConfig {
    applicationId "com.wmt.android.troopool"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "0.1"
    multiDexEnabled true
    renderscriptTargetApi 18
    renderscriptSupportModeEnabled true
    vectorDrawables.useSupportLibrary = true
}

compile 'com.android.support:support-vector-drawable:23.2.0'
compile 'com.android.support:animated-vector-drawable:23.2.0'

vectorDrawables。useSupportLibrary=true和gradle文件中的两个依赖项。

但它在4.4.2中显示了相同的错误。

共有1个答案

隆芷阳
2023-03-14

嘿,要在Lollipop下面的android上使用矢量绘图,您需要将代码中的图像放在这里,这里有一些功能可以帮助您随心所欲

public static enum DrawablePosition {
    Left, Right, Top, Bottom
}

public static Drawable getDrawable(Context context, int drawable) {
    return DrawableCompat.wrap(VectorDrawableCompat.create(context.getResources(), drawable, null));
}

public static Drawable getDrawableWithColor(Context context, int drawableResId, int IntColorOfDrawable) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), drawableResId, null);
    DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, IntColorOfDrawable);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    return drawable;
}

public static void setDrawableWithColorForIds(AppCompatActivity activity, int color, int[] ids, int drawable[]) {
    for (int i = 0; i != ids.length; i++) {
        Drawable drawable1 = VectorDrawableCompat.create(activity.getResources(), drawable[i], null);
        DrawableCompat.wrap(drawable1);
        DrawableCompat.setTint(drawable1, color);
        DrawableCompat.setTintMode(drawable1, PorterDuff.Mode.SRC_IN);
        ((TextView) activity.findViewById(ids[i])).setCompoundDrawablesWithIntrinsicBounds(drawable1, null, null, null);
    }
}

public static void placeVectorOnTextView(Context context, TextView textView, int vectorDrawableResID, @Nullable Integer VectorColor, DrawablePosition position) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), vectorDrawableResID, null);
    DrawableCompat.wrap(drawable);
    if (VectorColor != null){
        DrawableCompat.setTint(drawable, VectorColor);
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    }
    switch (position) {
        case Left:
            textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
            break;
        case Bottom:
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            break;
        case Right:
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            break;
        case Top:
            textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            break;

    }

}

public static void placeVectorOnEditText(Context context, EditText editText, int vectorDrawableResID, int VectorColor, DrawablePosition position) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), vectorDrawableResID, null);
    DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, VectorColor);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    switch (position) {
        case Left:
            editText.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
            break;
        case Bottom:
            editText.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            break;
        case Right:
            editText.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            break;
        case Top:
            editText.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            break;

    }

}

public static void placeVectorOnButton(Context context, Button button, int vectorDrawableResID, int VectorColor, DrawablePosition position) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), vectorDrawableResID, null);
    DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, VectorColor);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    switch (position) {
        case Left:
            button.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
            break;
        case Bottom:
            button.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            break;
        case Right:
            button.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            break;
        case Top:
            button.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            break;

    }

}

public static void placeVectorOnRadioButton(Context context, RadioButton radioButton, int vectorDrawableResID, int VectorColor, DrawablePosition position) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), vectorDrawableResID, null);
    DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, VectorColor);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    switch (position) {
        case Left:
            radioButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
            break;
        case Bottom:
            radioButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            break;
        case Right:
            radioButton.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            break;
        case Top:
            radioButton.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            break;

    }

}

public static void placeVectorOnCheckBox(Context context, CheckBox checkBox, int vectorDrawableResID, int VectorColor, DrawablePosition position) {
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), vectorDrawableResID, null);
    DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, VectorColor);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    switch (position) {
        case Left:
            checkBox.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
            break;
        case Bottom:
            checkBox.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            break;
        case Right:
            checkBox.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            break;
        case Top:
            checkBox.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
            break;

    }

}
 类似资料:
  • 支持向量机 概述 支持向量机(Support Vector Machines, SVM):是一种监督学习算法。 支持向量(Support Vector)就是离分隔超平面最近的那些点。 机(Machine)就是表示一种算法,而不是表示机器。 支持向量机 场景 要给左右两边的点进行分类 明显发现:选择D会比B、C分隔的效果要好很多。 支持向量机 原理 SVM 工作原理 对于上述的苹果和香蕉,我们想象为

  • 支持向量机(Support Vector Machine,SVM它是一种二类分类模型,其基本模型定义为特征空间上的间隔最大的线性分类器,学习策略是间隔最大化,最终可转化为一个凸二次规划问题的求解。 直观来看,位于两类训练样本“正中间”的划分超平面效果最好,即中间最粗的那条。 一般使用支持向量机时还会使用核函数,这样支持向量机会成为实质上的非线性分类器。 基本概念 在样本空间中,划分超平面可以定义为

  • 我正在尝试应用文本排序算法,不幸的是,我有一个错误 我有以下错误: 回溯(最近一次呼叫最后一次): 文件“bayes_classif.py”,第22行,在 数据集=pd。read_csv('train.csv',编码='utf-8') 文件“/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py”,第678行,在解析器中 返回读取(文

  • 支持向量机(SVM)是个非常强大并且有多种功能的机器学习模型,能够做线性或者非线性的分类,回归,甚至异常值检测。机器学习领域中最为流行的模型之一,是任何学习机器学习的人必备的工具。SVM 特别适合应用于复杂但中小规模数据集的分类问题。 本章节将阐述支持向量机的核心概念,怎么使用这个强大的模型,以及它是如何工作的。 线性支持向量机分类 SVM 的基本思想能够用一些图片来解释得很好,图 5-1 展示了

  • 支持向量机(SVM)是个非常强大并且有多种功能的机器学习模型,能够做线性或者非线性的分类,回归,甚至异常值检测。机器学习领域中最为流行的模型之一,是任何学习机器学习的人必备的工具。SVM 特别适合应用于复杂但中小规模数据集的分类问题。 本章节将阐述支持向量机的核心概念,怎么使用这个强大的模型,以及它是如何工作的。 线性支持向量机分类 SVM 的基本思想能够用一些图片来解释得很好,图 5-1 展示了

  • 最近在看斯坦福大学的机器学习的公开课,学习了支持向量机,再结合网上各位大神的学习经验总结了自己的一些关于支持向量机知识。 一、什么是支持向量机(SVM)? 1、支持向量机(Support Vector Machine,常简称为SVM)是一种监督式学习的方法,可广泛地应用于统计分类以及回归分析。支持向量机属于一般化线性分类器,这族分类器的特点是他们能够同时最小化经验误差与最大化几何边缘区,因此支持向