0

Good morning,

I'm trying to use SVG file instead of multiple PNG files but unfortunately, my ImageView is not showing anything. I already tried this : Android vector drawable app:srcCompat not showing images

Here is my code.

task_detail.axml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/BackgroundTest"
    android:padding="8dp"
    android:layout_weight="16">
    <android.support.v7.widget.AppCompatImageView
      android:id="@+id/imgVector"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"
      app:srcCompat="@drawable/link"
      android:layout_width="100dp"
      android:layout_height="100dp" />
</RelativeLayout>

task_detail.cs

class task_detail : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.task_detail);

            //Fix for white Status Bar
            Window window = this.Window;
            window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            window.SetStatusBarColor(new Color(ContextCompat.GetColor(this, Resource.Color.BackgroundTest)));

            //Trying to set SVG as src
            AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
            Android.Support.V7.Widget.AppCompatImageView imgVector = FindViewById<Android.Support.V7.Widget.AppCompatImageView>(Resource.Id.imgVector);
            imgVector.SetImageResource(Resource.Drawable.link);
        }

    }

Changing xmlns:app to http://schemas.android.com/tools is giving me errors : app:elevation isn't working with it so I'm not using it.

Thanks for your help !

  • I saw that in code behind you also defined the resource for imageview `imgVector.SetImageResource(Resource.Drawable.link);`, try to remove the `app:srcCompat="@drawable/link"` in xml and see if it works, I just created a demo for testing, both methods works by my side, and I just use `ImageView`, cause your activity is derive from `AppCompatActivity` so that the `AppCompatImageView` is automatically used at runtime where you have defined `ImageView` types. I doubt there is something wrong with your link.xml under drawable folder. – Grace Feng Jul 05 '17 at 06:19
  • Thanks for your comment, so I use normal ImageView now and I removed srcCompat as suggested but it doesn't change anything : I'm seeing only my background. Here is my SVG [link](https://pastebin.com/dpDXNQsx) but it's coming right from Adobe Illustrator so it's strange if the problem is coming from it... – Clément POIRET Jul 05 '17 at 07:42
  • Yeah, I used vector to create svg, and it works fine, seems third-party lib is needed to directly load svg file. Try to read this blog: [ Using SVGs in Xamarin.Android](https://medium.com/@_jamesmundy/using-svgs-in-xamarin-android-18d46d2f027d). – Grace Feng Jul 05 '17 at 08:02
  • Thanks for your answer, so I'm trying to use a vector instead, I've never used it before. Changing height and width aren't working (but vector's position is chaging", and gradient appears as a solid StartColor... Here is my code : [link](https://pastebin.com/kW6ApNbJ) and here is what I see : http://imgur.com/a/9nlgv EDIT : for size, I just saw my mistake, but gradient is still "solid" – Clément POIRET Jul 05 '17 at 09:13
  • Which height and width are you trying to change? I reset the layout height and width of `ImageView`, still works fine... – Grace Feng Jul 05 '17 at 09:22
  • You can check the gif of my test [here](https://i.stack.imgur.com/SRQu3.gif). It's a random size. Still what do you want to achieve? – Grace Feng Jul 05 '17 at 09:30
  • Size is now good, I just made a little mistake. I just have trouble to apply a gradient to the vector to make it looking like the original SVG file – Clément POIRET Jul 05 '17 at 11:54

0 Answers0