I need your help figuring out why I can’t get a shadow behind the center button on Android. I have it working in iOS just fine, but it doesn’t work.
This is my iOS handler appearance
iOS Image
Android Image
Here is the code in my Android handler itself – can anyone help me figure out how to give a shadow appearance behind the center circle?
public override View? OnCreateView(LayoutInflater inflater, ViewGroup? container, Bundle? savedInstanceState)
{
var view = base.OnCreateView(inflater, container, savedInstanceState);
if (Context is not null && ShellItem is ArtemisBar { CenterVisible: true } tabBar)
{
var rootLayout = new FrameLayout(Context)
{
LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
};
rootLayout.AddView(view);
const int middleViewSize = 100;
var middleViewLayoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutMargins.WrapContent,
ViewGroup.LayoutMargins.WrapContent,
GravityFlags.CenterHorizontal | GravityFlags.Bottom)
{
BottomMargin = 40
};
var middleView = new Button(Context)
{
LayoutParameters = middleViewLayoutParams
};
middleView.Click += delegate
{
tabBar.CenterCommand?.Execute(null);
};
middleView.SetPadding(0, 0, 0, 0);
middleView.SetShadowLayer(5,0,-20,Colors.DarkGray.ToPlatform());
if (tabBar.CenterBackgroundColor is not null)
{
var backgroundView = new View(Context)
{
LayoutParameters = middleViewLayoutParams
};
var backgroundDrawable = new GradientDrawable();
backgroundDrawable.SetShape(ShapeType.Rectangle);
backgroundDrawable.SetCornerRadius(middleViewSize / 4f);
backgroundDrawable.SetColor(tabBar.CenterBackgroundColor.ToPlatform(Colors.Green));
backgroundDrawable.Thickness = 2;
backgroundView.SetBackground(backgroundDrawable);
backgroundView.SetElevation(1);
rootLayout.AddView(backgroundView);
}
tabBar.CenterIcon?.LoadImage(Application.Current!.MainPage!.Handler!.MauiContext!, result =>
{
if (result?.Value is not BitmapDrawable drawable || drawable.Bitmap is null)
{
return;
}
const int padding = 20;
middleView.LayoutParameters = new FrameLayout.LayoutParams(
drawable.Bitmap.Width - padding,
drawable.Bitmap.Height - padding,
GravityFlags.CenterHorizontal | GravityFlags.Bottom)
{
BottomMargin = middleViewLayoutParams.BottomMargin - (int)(.65 * padding)
};
middleView.SetShadowLayer(2,0,0,Colors.LightGray.ToPlatform());
middleView.SetBackground(drawable);
middleView.SetShadowLayer(8,0,-100, Colors.DarkGray.ToPlatform());
middleView.SetMinimumHeight(0);
middleView.SetMinimumWidth(0);
middleView.SetElevation(1);
});
rootLayout.AddView(middleView);
return rootLayout;
}
return view;
}
Most of the code in my handler came from blog posts and reading other’s work on getting a custom tabbar, so some of the nuances of what’s happening in the handlers OnCreateView() are beyond me, but no matter what I tweak it doesn’t seem to change the Android appearance.