1

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?

Cfun
  • 8,442
  • 4
  • 30
  • 62
SoftDev
  • 277
  • 1
  • 3
  • 13
  • In general, the answer to tweaking via a custom renderer is: 1) find out what native class is used to represent that view. 2) Look at the methods available on that native class. Hopefully you will find that the platform class has a way to disable that underline. – ToolmakerSteve Jun 10 '21 at 18:30

2 Answers2

1
  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);
        }
    }
}
Cfun
  • 8,442
  • 4
  • 30
  • 62
  • Thank you. This is working fine. How to do this ios? – SoftDev Jun 11 '21 at 07:16
  • sorry I don't know for iOS part for now, if i figured out something I will update, or someone else could provide an answer for iOS – Cfun Jun 11 '21 at 11:52
0

You can use custom renderers with material visual to achieve entry underline removal. I am using the below code to apply it for all entries in the project and it is working with Xamarin Forms 4.8+

Xamarin Android

Entry

[assembly: ExportRenderer(typeof(Entry), typeof(EntryMaterialRendererAndroid), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace XFTest.Droid.Renderers
{
    public class EntryMaterialRendererAndroid : MaterialEntryRenderer
    {
        public EntryMaterialRendererAndroid(Context context) : base(context) { }
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.BoxStrokeWidth = 0;
                Control.BoxStrokeWidthFocused = 0;
            }
        }
    }
}

Xamarin iOS

Entry

[assembly: ExportRenderer(typeof(Entry), typeof(EntryMaterialRendereriOS), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace XFTest.iOS.Renderers
{
    public class EntryMaterialRendereriOS : MaterialEntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            EntryRemoveUnderLine();
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            EntryRemoveUnderLine();
        }

        protected void EntryRemoveUnderLine()
        {
            if (Control != null)
            {
                Control.BorderStyle = UITextBorderStyle.None;
                Control.Underline.Enabled = false;
                Control.Underline.DisabledColor = UIColor.Clear;
                Control.Underline.Color = UIColor.Clear;
                Control.Underline.BackgroundColor = UIColor.Clear;
                Control.ActiveTextInputController.UnderlineHeightActive = 0f;
                Control.PlaceholderLabel.BackgroundColor = UIColor.Clear;
            }
        }
    }
}