I have used a customShellHandler to make a tabBar in my home screen placed bottom of my screen. Since I used margin and radius, the background of tab show as white. I wanted to make it transparent to display the content page's color This is How my page looks
Here is my AppShell.XAML
<TabBar >
<Tab Title="Add New" >
<ShellContent
ContentTemplate="{DataTemplate local:AddNewAwake}"
Route="AddNewAwake" />
</Tab>
<Tab Title="Upcoming">
<ShellContent
ContentTemplate="{DataTemplate local:UpcomingAwake}"
Route="UpcomingAwake" />
</Tab>
</TabBar>
---Below is my CustomHandler
internal class CustomShellBottomNavViewAppearanceTracker(IShellContext shellContext, ShellItem shellItem)
: ShellBottomNavViewAppearanceTracker(shellContext, shellItem)
{
private readonly IShellContext shellContext = shellContext;
public static Color color = Colors.Red;
public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
base.SetAppearance(bottomView, appearance);
if (Shell.GetTabBarIsVisible(shellContext.Shell.CurrentPage))
{
var backgroundDrawable = new GradientDrawable();
backgroundDrawable.SetShape(ShapeType.Rectangle);
backgroundDrawable.SetCornerRadius(30);
backgroundDrawable.SetColor(appearance.EffectiveTabBarBackgroundColor.ToPlatform());
bottomView.SetBackground(backgroundDrawable);
var layoutParams = bottomView.LayoutParameters;
if (layoutParams is ViewGroup.MarginLayoutParams marginLayoutParams)
{
const int margin = 30;
marginLayoutParams.BottomMargin = margin;
marginLayoutParams.LeftMargin = margin;
marginLayoutParams.RightMargin = margin;
bottomView.LayoutParameters = layoutParams;
}
}
}
}
I want the background of my tab to be transparent
Take the gray background in your picture as an example:
Create
styles.xml
file in Platforms/Android/Resources/values, and set itsBuild Action
toAndroidResource
:Change
@style/Maui.SplashTheme
toTheme = "@style/MyTheme"
:In your CustomShellBottomNavViewAppearanceTracker:
And your appshell: