.net 毛伊岛底部(导航)选项卡栏顶部(边框)行



如何在Android和IOS上的标签栏上方获得水平线? 下面是一个关于 xamarin 表单的堆栈溢出的类似问题。我尝试使用新的处理程序。但我不知道我做得对不对。

Microsoft.Maui.Handlers.TabbedViewHandler.Mapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
{
if (view is BottomNavigationView )
{
#if __ANDROID__
Android.Graphics.Drawables.ShapeDrawable line = new()
{
Alpha = 255
};
line.Paint.Color = Colors.Black.ToAndroid();
line.Paint.SetStyle(Android.Graphics.Paint.Style.Fill);
var layerDrawable = new LayerDrawable(new Drawable[] { line });
layerDrawable.SetLayerInset(0, 0, 0, 0, int.Parse((view.Height - 4).ToString()));
(handler.PlatformView as global::Android.Views.View).SetBackground(layerDrawable);

#endif
}
});

创建跨平台 .NET MAUI 自定义控件(其平台实现由handlers提供)的过程如下所示:

  1. 为跨平台控件创建一个类,该类提供 控件的公共 API。有关详细信息,请参阅此处。

  2. 创建任何所需的其他跨平台类型。

  3. 创建分部处理程序类。有关详细信息,请参阅创建 处理器。

  4. 在处理程序类中,创建一个 PropertyMapper 字典,该字典 定义跨平台属性更改时要执行的操作 发生。有关详细信息,请参阅创建属性映射器。

  5. (可选)在处理程序类中,创建一个命令映射器 字典,它定义了在 跨平台控件将指令发送到本机视图 实现跨平台控制。有关详细信息,请参阅 创建命令映射器。

  6. 为每个平台创建分部处理程序类,以创建 实现跨平台控件的本机视图。欲了解更多信息 信息,请参阅创建平台控件。

  7. 使用 ConfigureMauiHandlers 和 AddHandler 注册处理程序 应用的 MauiProgram 类中的方法。有关详细信息,请参阅 注册处理程序。

.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(CustomControl), typeof(CustomControlHandler));
});

参考链接:https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/

Sample repo:https://github.com/dotnet/maui-samples/tree/main/6.0/UserInterface/Handlers/CreateHandlerDemo