image files in Resources drawable do not appear in Xamrin.Forms Android

Jeff Whattam 101 Reputation points

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:


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?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,151 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeff Whattam 101 Reputation points

    @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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 53,756 Reputation points Microsoft Vendor


    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 to Resources/drawable folder. Please open your project folder delete bin and obj 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));  
                   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.


    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.