How to integrate .NET MAUI TabView with Android native embedding?
In this article, you can learn how to create a .NET MAUI TabView native-embedded Android application by following the step-by-step process explained as follows:
Step 1:
Create a .NET Android application and install the Syncfusion.Maui.TabView Nuget package.
Step 2:
In the project file of the native application, add <UseMaui>true</UseMaui>
to enable the .NET MAUI support demonstrated as follows.
<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseMaui>true</UseMaui>
</PropertyGroup>
Step 3:
Creating a MauiAppBuilder
object and using the UseMauiEmbedding
function is the standard procedure for initializing .NET MAUI in a native app project.
Use the Build()
method on the MauiAppBuilder
object to build a MauiApp object. From the MauiApp object, a MauiContext object should be created. Converting .NET MAUI controls to native types will involve using the MauiContext
object.
MauiContext? _mauiContext;
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
builder.ConfigureSyncfusionCore();
MauiApp mauiApp = builder.Build();
_mauiContext = new MauiContext(mauiApp.Services, this);
}
Step 4:
Initialize the TabView
control.
MauiContext? _mauiContext;
protected override void OnCreate(Bundle? savedInstanceState)
{
...
SfTabView tabView = new SfTabView();
ListView listView = new ListView
{
RowHeight = 50,
ItemsSource = new string[] { "James", "Richard", "Clara", "Michael", "Alex", "Clara" },
ItemTemplate = new DataTemplate(() =>
{
var grid = new Grid
{
Margin = new Thickness(10, 5)
};
var label = new Label
{
...
};
label.SetBinding(Label.TextProperty, ".");
grid.Children.Add(label);
return new ViewCell { View = grid };
})
};
Grid favoritesGrid = new Grid { };
favoritesGrid.Children.Add(listView);
...
var tabItems = new TabItemCollection
{
new SfTabItem()
{
Header = "FAVOURITES",
Content = favoritesGrid
},
...
};
tabView.Items = tabItems;
...
}
Step 5:
Convert the Tab View to a platform-specific view for the MAUI framework and set this view as the content view for the current Android activity.
protected override void OnCreate(Bundle? savedInstanceState)
{
Android.Views.View mauiView = tabView.ToPlatform(_mauiContext);
SetContentView(mauiView);
}
Output
Download the complete sample on GitHub
Conclusion
Hope you enjoyed learning about how to integrate .NET MAUI TabView with an Android native embedding application.
You can refer to our .NET MAUI Tab View’s feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI Tab View documentation to understand how to present and manipulate data.
For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI Tab View and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!