【问题标题】:The underline of entry cannot removed条目下划线无法删除
【发布时间】:2019-04-16 01:54:33
【问题描述】:

我想输入一个不带下划线的条目。我尝试了两种解决方案,但都无法正常工作。

Control.Background = null;

不顺利,我采取了另一种解决方案:

GradientDrawable gd = new GradientDrawable();
            gd.SetColor(global::Android.Graphics.Color.Transparent);
            Control.SetBackground(gd);
            this.Control.SetRawInputType(Android.Text.InputTypes.TextFlagNoSuggestions);
            Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.White));

它在android中也不好,但在ios中运行良好。我不明白为什么。

【问题讨论】:

  • dzone.com/articles/… 如果只有人们在倾倒他们的问题之前使用谷歌!
  • 嗨@Ali123我无法打开谷歌你知道。除了文章的解决方案我之前尝试过。
  • 你在使用自定义渲染器吗?
  • @Batuhan 嗨,我发现错误在哪里。
  • 无法打开google是什么意思?如果您无法打开 google,您希望如何对其进行身份验证?

标签: xamarin.forms


【解决方案1】:

您可以尝试添加名为editText_bg.xml的xml样式,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#FFFFFF" />
    <stroke
        android:width="1dp"
        android:color="#2f6699" />
    <corners 
        android:radius="10dp"            
        />
</shape>

您可以将其作为后台资源提供给条目:

[assembly: ExportRenderer(typeof(CustomEntry), typeof(AndroidCustomEntryRenderer))]
namespace XXX.Droid.Renderer
{
    public class AndroidCustomEntryRenderer : EntryRenderer
    {
        public AndroidCustomEntryRenderer(Context context) : base(context)
        {
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.SetBackgroundColor(global::Android.Graphics.Color.White);
                Control.SetBackgroundResource(Resource.Drawable.edittext_bg);
            }
        }
    }
} 

【讨论】:

  • 它可以解决你的问题。
【解决方案2】:

试试我的实现(适用于 Android 和 ios)。 PlainEntry 是继承自 Xamarin.Forms.Entry 的空类

安卓

[assembly: ExportRenderer(typeof(PlainEntry), typeof(PlainEntryRenderer))]
namespace UR.Droid.Renderers
{
    public class PlainEntryRenderer : EntryRenderer
    {
        public PlainEntryRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                this.Control.
                    SetBackgroundColor(global::Android.Graphics.Color.Transparent);
                Control.SetPadding(0, 0, 0, 0);
            }
        }
    }
}

iOS

[assembly: ExportRenderer(typeof(PlainEntry), typeof(PlainEntryRenderer))]
namespace UR.iOS.Renderer
{
    class PlainEntryRenderer: EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.BorderStyle = UITextBorderStyle.None;
                Control.BackgroundColor = UIColor.FromRGBA(0, 0, 0, 0);
            }
        }
    }
}

如果您想为所有 Xamarin.Forms.Entry 使用渲染器,例如不指定:

[assembly: ExportRenderer(typeof(Xamarin.Forms.Entry), typeof(PlainEntryRenderer))]

【讨论】:

    猜你喜欢
    • 2016-05-14
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    • 2022-01-15
    • 2020-05-19
    • 2020-01-18
    • 2016-08-26
    • 2017-03-23
    相关资源
    最近更新 更多