Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms image not showing-Android

I have a Xamarin Forms Android app and when I'm using the following code

 var image = new Image { Source = "lock.png" };

to show an image, but the image isn't showing though.

And then I try to change the source to Icon.png (the default Xamarin icon) and it working fine.

Does anybody know how to make this image show in my app?

(ps: image path : ".\MyApp.Droid\Resources\drawable\lock.png".)

like image 600
Lilly White Avatar asked May 25 '16 02:05

Lilly White


4 Answers

I also faced to this issue. I tried above mentioned two solutions too. But didn't. People can try below suggestions one by one,

  • In Solution Explorer -> right click on image -> select "Include to project"
  • Go to image properties -> Build Action -> set to "Android Resource"
  • Check whether your image file name contains dashes or hyphens
  • Clean the project
  • Build the project and Run the project

I didn't build the project, after adding the image. It was my problem. May someone get benefited from my answer.

like image 149
Mohan Perera Avatar answered Nov 12 '22 11:11

Mohan Perera


Make sure that image has Build Action set to "Android Resource". Otherwise, it is not copied to final package properly and there is no image for app to show. This is described in guide here: https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Local_Images

like image 36
Anton Tarasov Avatar answered Nov 12 '22 10:11

Anton Tarasov


Another problem could be that the image is too large to be rendered. If everything else fails, try creating a smaller version of the image.

I hope this helps somebody.

like image 31
Plaba Avatar answered Nov 12 '22 12:11

Plaba


For others who may come here, also check to make sure your image doesn't have dashes/hyphens in the file name as per https://stackoverflow.com/a/35760195/908677 - that was why my image wasn't showing up.

like image 2
Elijah Lofgren Avatar answered Nov 12 '22 10:11

Elijah Lofgren