Hello,
You can refer to the following steps to use this xml file in Maui.
Step 1. Create this xml file into Android/Resources/Drawable folder and set its Build Action to AndroidResource.
Step 2. Creating custom controls in Maui.
public class MyLabel:Label
{
}
Step 3. Create a corresponding Handler in the Android folder to use the custom shape.
public class MyLabelHandler:LabelHandler
{
protected override void ConnectHandler(AppCompatTextView platformView)
{
base.ConnectHandler(platformView);
var t = this.PlatformView as TextView;
if (t != null)
{
t.SetBackgroundResource(Resource.Drawable.test_shape);
}
}
}
Step 4. Register this Handler in the Maui project.
.ConfigureMauiHandlers(handlers =>
{
#if ANDROID
handlers.AddHandler(typeof(MyLabel), typeof(MauiApp5.Platforms.Android.MyLabelHandler));
#endif
})
Step 5. Use this custom control in Xaml.
<local:MyLabel
Text="Hello, World!"/>
You could refer to the following documentation for more detailed information about handler.
Best Regards,
Alec Liu.
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.