Reputation: 4772
I've a Xamarin Forms project - with the 3 projects for UWP, iOS and Android. Now I want to use images in my Xamarin Pages. As intended by Xamarin I want to use the same code for all three targets ... e.g.:
<Image Source="Assets/appIcon-256.png"/>
This works for iOS and UWP - both have a folder "Assets" where I placed the image. Ok, I've to maintain the image twice, but I've the same XAML code for both project.
But for Android, that doesn't seems to work. The image is not displayed in Android, if I put the png in the Assets folder of the Anroid project.
What can I do to use the same location for all images for all the three projects?
Upvotes: 2
Views: 5576
Reputation: 381
It's very easy.
IOS => You need put the images on "Resources" (note: no more routes) , for ANDROID => you need put the images on "Resources/drawable" .for UWP => put the images on root project UWP.
On Diferents platforms the images have diferents routes.
Then on the xaml files you can put <Image Source="imageName.jpg" />
Send feedback please.
UPDATE
You can put the images on UWP/Assets and then :
<ToolbarItem
Text="Search">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="Android, iOS" Value="movies-search.png"/>
<On Platform="UWP" Value="Assets/movies-search.png"/>
</OnPlatform>
</ToolbarItem.Icon>
</ToolbarItem>
Upvotes: 4
Reputation: 126
Replace your dashes with underscores. Example, ic_launcher_calendar.png
Try also to remove the digits at the end of the name.
Lastly, you can check out the naming conventions of drawable. http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/
Let me know if it works.
Upvotes: 0
Reputation: 203
Why the path starting with "Assets/"? For Android Place your image to MyProject.Android/Resources/drawable. For iOS myProject.iOS/Resources/ and in xaml
<Image Source="appIcon-256.png"/>
It will work. In addition for iOS if you have same picture with different sizes, you should rename them like "appIcon-256.png" "[email protected]" "[email protected]"
Upvotes: 2