how can i add a 'shell level' control?(customizing tabbar)

尼龟 杰 150 Reputation points
2023-12-16T09:50:06.9966667+00:00

like the gif, no matter how i toggle page , the 'shell level' control always keep the same.

28a532e5c2dbc1efb90b -middle-original

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,889 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
765 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 尼龟 杰 150 Reputation points
    2023-12-19T10:00:51.59+00:00

    only find that on customizing tabbar on android

    
                .ConfigureMauiHandlers(handlers =>              {
    #if __ANDROID__
                     handlers.AddHandler(typeof(Shell), typeof(cshell)); 
    #endif
                 });
    
    
        public class cshell : ShellRenderer
         {
             protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
             {
                 return new CustomShellItemRenderer(this);
             }
           }
         internal class CustomShellItemRenderer : ShellItemRenderer
         {
             public CustomShellItemRenderer(IShellContext context) : base(context)
             {         }
             public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
             {
                  var view = base.OnCreateView(inflater, container, savedInstanceState);
                  if (Context is not null && ShellItem is TabBar tabbar)
                 {
                     var rootLayout = new FrameLayout(Context)
                     {
                         LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
                     };
                     rootLayout.AddView(view);
                     const int middleViewSize = 150;
                     var middleViewLayoutParams = new FrameLayout.LayoutParams(
                         ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent,
                         GravityFlags.CenterHorizontal | GravityFlags.Bottom)
                     {
                         BottomMargin = 100,
                         Width = middleViewSize,
                         Height = middleViewSize
                     };
                     var middleView = new Button(Context) { LayoutParameters = middleViewLayoutParams };
                      rootLayout.AddView(middleView);
                     return rootLayout;
                  }
                 return view;
              }
          }
    
    1 person found this answer helpful.
    0 comments No comments