Hello,
You do not add the view to the rootLayout by rootLayout.AddView(view);
, please add it.
Here is my tested code in OnCreateView
method.
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = base. OnCreateView(inflater, container, savedInstanceState);
if (Context is not null && ShellItem is CustomTabBar { CenterViewVisible: true } 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 }; middleView.Click += delegate { tabbar. CenterViewCommand?. Execute(null); };
rootLayout.AddView(middleView);
return rootLayout;
}
return view;
}
By the way, please do not forget to register this custom renderer in the CreateMauiApp
method of MauiProgram.cs
builder
.ConfigureMauiHandlers(handlers =>
{
#if ANDROID
handlers.AddHandler(typeof(Shell), typeof(yourProject.Platforms.Android.CustomShellRenderer));
#endif
});
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.