Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 816
peter.o Avatar asked Dec 05 '25 10:12

peter.o


1 Answers

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);
like image 130
peter.o Avatar answered Dec 06 '25 23:12

peter.o



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!