【发布时间】:2019-01-04 19:55:04
【问题描述】:
在 Xamarin Forms (3.0) 应用程序中,我将使用什么方法从共享项目代码中判断我的 Android 项目中是否存在可绘制资源?
在 iOS 中,我可以使用 NSFileManager 查看文件是否存在于我的 iOS 项目的“资源”文件夹中:
#if __IOS__
private bool DoesImageExist(string image)
{
//WORKS
return Foundation.NSFileManager.DefaultManager.FileExists(image);
}
#endif
在 Android 中,我认为它应该是程序集资源的一部分,但这只是返回我的 App.xaml 文件。
#if __ANDROID__
private bool DoesImageExist(string image)
{
//DOES NOT WORK
if(MyApp.Current?.GetType() is Type type)
foreach (var res in Assembly.GetAssembly(type).GetManifestResourceNames())
{
if (res.Equals(image, StringComparison.CurrentCultureIgnoreCase))
return true;
}
return false;
}
#endif
【问题讨论】:
标签: android xamarin.forms resources drawable