Search code examples
androidnativescriptandroid-vectordrawable

VectorDrawable as Image source in NativeScript


I'm trying to use android's VectorDrawable as Image source in NativeScript. Using layout inspector I can see that there is something but no image is displayed. Also there is no error about missing image file, no errors at all.

I couldn't find out whether it's possible or not.

Thanks a lot in advance.


Solution

  • So I somehow figured it out:

    let context = application.android.context;
    // vector is VectorDrawable name
            let logo = context.getResources()
                .getIdentifier(this.vector, "drawable", context.getPackageName());
            this.el.nativeElement.android.setBackgroundResource(logo);
    
            // Access CSS color to change fill color
            let backgroundColor: string = (this.el.nativeElement.backgroundColor)
                ? this.el.nativeElement.backgroundColor.toString()
                : SrcDirective.DEFAULT_COLOR;
    
            let newBackgroundColor: Color = new Color(backgroundColor);
    
            this.el.nativeElement.android.getBackground().setTint(newBackgroundColor.android);