使用矢量作为drawable时Xamarin.Android错误

时间:2017-02-07 14:03:15

标签: android xamarin.android android-vectordrawable

我尝试使用矢量图像作为按钮的背景。它需要在API 19+上得到支持,所以我添加了Xamarin.Android.Support.v7.AppCompat NuGet包和Xamarin.Android.Support.VectorDrawable

<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Compat" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Fragment" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Media.Compat" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Percent" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.0" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.0" targetFramework="monoandroid70" />

矢量定义文件(resources/drawable/key_visual.xml)如下:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="135.08dp"
    android:height="141.35dp"
    android:viewportWidth="135.08"
    android:viewportHeight="141.35">

<path
    android:fillColor="#004e9a"
    android:pathData="M64,140.83 A25.66,25.66,0,0,1,45.51,132.93 L37.2,124.22
        A18.2,18.2,0,0,0,33.8,121.42 L32.44,120.55 A56.79,56.79,0,0,1,0.52,69.29
        C0.52,39.87,22.52,14.93,51.75,11.99 L51.9,11.99 L69.77,3.39
        A26.45,26.45,0,0,1,100.43,8.24 L126.85,34.66 A26.34,26.34,0,0,1,131.71,65.32
        L126.81,74.94 C126.66,75.52,126.54,75.94,126.4,76.43 L123,88
        A18.4,18.4,0,0,0,122.28,92.35 L121.75,104.35 A25.64,25.64,0,0,1,102.26,128
        L90.56,130.84 A18.09,18.09,0,0,0,86.43,132.39 L75.75,138
        A25.55,25.55,0,0,1,64,140.83 Z" />
<path
    android:fillColor="#fdb71a"
    android:pathData="M115.9,47.29 L108.69,42.69 A57.62,57.62,0,0,1,32.16,121 L33.53,121.87
        A17.69,17.69,0,0,1,36.84,124.59 L45.15,133.3 A26.07,26.07,0,0,0,76,138.42
        L86.68,132.87 A17.6,17.6,0,0,1,90.68,131.37 L102.38,128.53
        A26.08,26.08,0,0,0,122.25,104.38 L122.78,92.38 A17.9,17.9,0,0,1,123.48,88.16
        L126.87,76.61 C127.01,76.14,127.13,75.67,127.24,75.2
        A26.08,26.08,0,0,0,115.9,47.29 Z" />
<path
    android:fillColor="#86bae4"
    android:pathData="M81.73,0 A26.84,26.84,0,0,0,69.53,2.93 L51.74,12 A58,58,0,0,1,57.59,11.71
        L57.59,11.71 A57.59,57.59,0,0,1,108.69,42.71 L115.9,47.31
        A26.08,26.08,0,0,1,127.25,75.19 L132.15,65.57 A27,27,0,0,0,127.15,34.31
        L100.79,7.88 A27,27,0,0,0,81.73,0" />
<path
    android:fillColor="#7275b7"
    android:pathData="M91.19,113.54 A26.87,26.87,0,0,1,86.99,113.21 L50.09,107.36
        A27,27,0,0,1,27.72,85 L21.87,48.09 A26.93,26.93,0,0,1,36.24,19.89 L51.74,12
        A57.6,57.6,0,1,0,94.74,113.31 A26.77,26.77,0,0,1,91.19,113.54 Z" />
</vector>

以下是我如何使用它:

...
<android.support.v7.widget.AppCompatButton
    local:srcCompat="@drawable/key_visual"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_weight=".75"
    android:textColor="#FFFFFF"
    android:text="open the door"
    android:id="@+id/doorOpen"
    local:MvxBind="Click MyCommand"/>
...

当我在模拟器上运行它时(在虚拟化的win10,Android 4.4 API19上)没有显示任何按钮,我在调试器控制台上收到以下错误:

02-07 13:32:01.689 I/dalvikvm( 1988): Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
02-07 13:32:01.689 W/dalvikvm( 1988): VFY: unable to resolve virtual method 563: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
02-07 13:32:01.689 D/dalvikvm( 1988): VFY: replacing opcode 0x6e at 0x0002
02-07 13:32:01.689 I/dalvikvm( 1988): Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
02-07 13:32:01.689 W/dalvikvm( 1988): VFY: unable to resolve virtual method 565: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
02-07 13:32:01.689 D/dalvikvm( 1988): VFY: replacing opcode 0x6e at 0x0002
02-07 13:32:01.693 I/dalvikvm( 1988): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
02-07 13:32:01.693 W/dalvikvm( 1988): VFY: unable to resolve virtual method 600: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
02-07 13:32:01.693 D/dalvikvm( 1988): VFY: replacing opcode 0x6e at 0x0002
02-07 13:32:01.693 I/dalvikvm( 1988): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
02-07 13:32:01.693 W/dalvikvm( 1988): VFY: unable to resolve virtual method 622: Landroid/content/res/TypedArray;.getType (I)I
02-07 13:32:01.693 D/dalvikvm( 1988): VFY: replacing opcode 0x6e at 0x0008
02-07 13:32:01.693 I/dalvikvm( 1988): Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
02-07 13:32:01.693 W/dalvikvm( 1988): VFY: unable to resolve virtual method 374: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
02-07 13:32:01.693 D/dalvikvm( 1988): VFY: replacing opcode 0x6e at 0x0006
02-07 13:32:01.693 D/Mono    ( 1988): Assembly Ref addref Xamarin.Android.Support.v7.AppCompat[0xb96b8190] ->     Xamarin.Android.Support.Compat[0xb96aff20]: 2

我试图重新安装所有软件包,但没有运气。有什么想法可能是什么?

0 个答案:

没有答案