NathanWalker / nativescript-fancyalert

Fancy alerts for NativeScript.
Other
147 stars 38 forks source link

How do you add an image in showColorDialog for android? #82

Closed dimitriospafos closed 4 years ago

dimitriospafos commented 4 years ago

How do I pass the "contentImage?" argument in showColorDialog?

showColorDialog( title: string, subTitle: string, okBtnTitle?: string, cancelBtnTitle?: string, backgroundColor?: string, titleTextColor?: string, contextTextColor?: string, contentImage?: any ): Promise;

I tried to pass the name of an image which exists in assets ? (e,g image.png) but it didn't work.

Rahul1d commented 4 years ago

Hi @dimitriospafos, You cannot pass image as string. You need to pass it as a resource.

You can use the following code;

var app = require("tns-core-modules/application"); 
var context = app.android.context;
var image = "@drawable/image";      //Place image name without extension. //Image should be placed in "~App_Resources\Android\src\main\res\drawable-xxx"

 var  resId = context.getResources().getIdentifier(image,null, context.getPackageName());
dimitriospafos commented 4 years ago

@Rahul1d thanks this worked.