Search code examples
c#androidxamarinxamarin.formscustom-renderer

How to remove visual material entry underline


We are using the visual material entry for our project.

using Xamarin.Forms.Material.Android;

[assembly: ExportRenderer(typeof(ProgressBar), typeof(CustomMaterialProgressBarRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace MyApp.Android
{
    public class CustomMaterialProgressBarRenderer : MaterialProgressBarRenderer
    {
        //...
    }
}

How to remove material entry underline?


Solution

    1. Create a dimension resource (Add a new .xml file and save it under your Android project in Resources\values)
    <?xml version="1.0" encoding="utf-8"?>
    <resources> 
    <dimen name="box_stroke_dim">0dp</dimen>
    </resources>
    
    1. Custom renderer implementation for every Entry with Visual="Material"
    [assembly: ExportRenderer(typeof(Entry), typeof(App.Droid.MyMaterialEntryRenderer),
                new[] { typeof(VisualMarker.MaterialVisual) })]
    
    namespace App.Droid
    {
        public class MyMaterialEntryRenderer : MaterialEntryRenderer
        {
            public MyMaterialEntryRenderer(Context context) : base(context)
            {
            }
    
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
    
                Control?.SetBoxStrokeWidthResource(Resource.Dimension.box_stroke_dim);
                Control?.SetBoxStrokeWidthFocusedResource(Resource.Dimension.box_stroke_dim);
            }
        }
    }