如何在 xamarin 表单 ios 中删除视觉材料条目下划线 条目条目

问题描述

我们正在为我们的项目使用视觉材料条目。

 using Xamarin.Forms.Material.IOS;

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

如何去除xamarin表单ios中的材料条目下划线?

解决方法

您可以将活动下划线高度设置为 0f 以实现此目的:

[assembly: ExportRenderer(typeof(CustomMaterialEntry),typeof(CustomMaterialEntryRenderer),new[] { typeof(VisualMarker.MaterialVisual) })]
namespace MyApp.iOS
public class CustomMaterialEntryRenderer : MaterialEntryRenderer
{

   protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
   {
      base.OnElementChanged(e);
      if (this.Control != null)
      {
        Control.ActiveTextInputController.UnderlineHeightActive = 0f;
      }

   }
}
,

您可以使用 custom renderersmaterial visual 来实现条目下划线的去除。 我正在使用以下代码将其应用于项目中的所有条目,并且它正在与 Xamarin Forms 4.8+ 一起使用

Xamarin 安卓

条目

[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

条目

[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;
            }
        }
    }
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...