正如我在标题中所写的,我使用微软的Xamarin.Forms.Maps块在我的应用程序中显示地图。首先,我开始使用Xamarin.Forms.GoogleMaps,但是当我发现我不能定制InfoWindows (当我触摸一个管脚时)时,我必须回去开始使用Xamarin.Forms.Maps。唯一的问题是,我必须将“灰色样式”应用到地图或类似的东西上。我找不到任何链接或指南来做这件事。似乎CustomRender不能修改样式或颜色。
有人能帮帮我吗?有任何链接、文档或示例吗?
发布于 2021-06-28 14:33:55
如果你指的是Dark Mode,你可以创建自定义渲染器来实现。
iOS
在OnElementChanged中设置OverrideUserInterfaceStyle。
[assembly: ExportRenderer(typeof(Map), typeof(MyRenderer))]
namespace FormsApp.iOS
{
class MyRenderer : MapRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var nativeMap = Control as MKMapView;
nativeMap.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Dark;
}
}
}
}安卓
在资源中创建暗模式文件,并在OnElementChanged中设置mapStyle。
[assembly: ExportRenderer(typeof(Map), typeof(MyMapRenderer))]
namespace FormsApp.Droid
{
class MyMapRenderer : MapRenderer
{
Context _context;
public MyMapRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
{
base.OnElementChanged(e);
if(e.NewElement != null)
{
NativeMap.SetMapStyle(MapStyleOptions.LoadRawResourceStyle(this.Context, Resource.Raw.map_style_night));
}
}
}
}请参阅
https://forums.xamarin.com/discussion/comment/429548/#Comment_429548。
https://stackoverflow.com/questions/68150658
复制相似问题