问题描述
我有一个Xamarin Forms 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.
然后我尝试将源更改为Icon.png(默认的Xamarin图标),并且可以正常工作.
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:图像路径:.\ MyApp.Droid \ Resources \ drawable \ lock.png".)
(ps: image path : ".\MyApp.Droid\Resources\drawable\lock.png".)
推荐答案
请确保该图像的构建操作"设置为"Android资源".否则,它不会正确复制到最终包装中,并且没有图像可供应用显示.此处的指南对此进行了说明: https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Local_Images
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
这篇关于Xamarin Forms图像未显示-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!