@Leon Lu (Shanghai Wicresoft Co,.Ltd.) I finally figured it out. Somehow I have to use the full path of the icon file. For example, if my project name is MyApp, I have to use MyApp.Droid.Resource.Drawable.Pin. Not sure why in the sample project, this is not needed and can be access as Resource.Drawable.Pin.
image files in Resources drawable do not appear in Xamrin.Forms Android
I have a custom map renderer where I want to add custom pin. I have the pin's image file added in Resources/drawable. But when I specifically used Android code to locate the file, I found that it didn't exist. The method I called is something like this:
BitmapDescriptorFactory.FromResource(Resource.Drawable.CustomPin);
I know that in native Android, the images will have an integer identification, so I think that CustomPin does not have its integer identification generated and that is why it cannot be found. If this is the case, what can I do to have the image files I put in Resources/drawable to have their integer ids generated?
1 additional answer
Sort by: Most helpful
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 74,486 Reputation points Microsoft Vendor
2021-05-20T05:54:38.883+00:00 Hello,
Welcome to our Microsoft Q&A platform!
Which error did you meet? Or you do not get any error, but image do not appear after setting it to pin of custom renderer map.
If you meet error:
'Resource.Drawable' does not contain a definition for 'icon1'
and you have added the image toResources/drawable
folder. Please open your project folder deletebin
andobj
folder, then rebuild your project.If you set the image to MarkerOptions's icon in custom renderer for map like following code, but these pins do not disappear.
protected override MarkerOptions CreateMarker(Pin pin) { var marker = new MarkerOptions(); marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude)); marker.SetTitle(pin.Label); marker.SetSnippet(pin.Address); marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.icon1)); return marker; }
You can refer to following samples about custom renderer for map. I set a new icon in custom renderer. it works like following screenshot.
https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/customrenderers-map-pin/Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.