Reputation: 357
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?
Upvotes: 1
Views: 938
Reputation: 69
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+
[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;
}
}
}
}
[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;
}
}
}
}
Upvotes: 0
Reputation: 9671
Resources\values
)<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="box_stroke_dim">0dp</dimen>
</resources>
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);
}
}
}
Upvotes: 1