我正在开发一个多平台 (Android/iOS) Xamarin.Forms 应用。
我放了一个 TabbedPage。我想为每个页面定义一个图标。我试过在 XAML 文件中设置图标属性:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XXXX.YYYY">
<TabbedPage.Children>
<ContentPage Title="Recherche" Icon="search.png">
当我在 iOS 模拟器中尝试 Xamarin 预览时出现错误和空白应用程序。
我的问题是:我应该把 search.png 文件放在哪里?
在共享项目中? 在特定的子文件夹中?
在每个 iOS/Android 子项目中?
最佳答案
图像 Assets 需要在每个特定于平台的项目上,以便它们针对每个操作系统正确调整大小、命名和格式。
阅读本文以更好地了解图像:Working with Images
iOS - Place images in the Resources folder with Build Action: BundleResource. Retina versions of the image should also be supplied - two and three times the resolution with a @2x or @3x suffixes on the filename before the file extension (eg. myimage@2x.png).
Android - Place images in the Resources/drawable directory with Build Action: AndroidResource. High- and low-DPI versions of an image can also be supplied (in appropriately named Resources subdirectories such as drawable-ldpi, drawable-hdpi, and drawable-xhdpi).
Windows Phone - Place images in the application's root directory with Build Action: Content.
Windows/UWP - Place images in the application's root directory with Build Action: Content.
正确放置图像后,您可以正确使用它们,例如 Icon="search.png"
。
关于android - 我应该在 Xamarin.Forms 的什么地方放置 TabbedPage 的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42272980/