How to remove the line under a text of an entry in a Xamarin application

XamarinDev 21 Reputation points
2021-01-21T08:59:56.33+00:00

Hello,

Can someone please help me with this issue

59122-entryfield.png

As you can see there is a line under the entered text which I don't want to show. I have created a custom entry renderer:

CustomEntry.cs

    public class CustomEntry : Entry  
    {  
  
    }  

CustomEntryRendererAndroid.cs

    public class CustomEntryRendererAndroid : EntryRenderer  
    {  
  
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)  
        {  
            base.OnElementChanged(e);  
  
            if (Control != null)  
            {  
                GradientDrawable gd = new GradientDrawable();  
  
                gd.SetColor(Android.Graphics.Color.Transparent);  
                this.Control.SetBackground(gd);  
                this.Control.SetPadding(20, 0, 0, 0);  
                 
            }  
        }  
  
        public CustomEntryRendererAndroid(Context context) : base(context)  
        {  
  
        }  
    }  

Does anyone know what I can do to not show the bottom line of an entered text?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,338 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 74,641 Reputation points Microsoft Vendor
    2021-01-21T09:36:37.2+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    You can set the this.Control.SetBackground(null); in the custom renderer.

    59133-image.png

    ============
    Update================
    You can try to set the TextVariationVisiblePassword for custom renderer of Entry.

    this.Control.InputType=InputTypes.TextVariationVisiblePassword;

    ================
    Update2==================

    I also need this custom entry for a password. Can I add like a condition to check if the enry is a password?

    Do you want to add property like following code?

       public class CustomEntry : Entry  
           {  
               public static readonly BindableProperty IsPasswordFlagProperty =  
               BindableProperty.Create("IsPasswordFlag", typeof(bool), typeof(CustomEntry), defaultBindingMode: BindingMode.OneWay);  
         
               public bool IsPasswordFlag  
               {  
                   get { return (bool)GetValue(IsPasswordFlagProperty); }  
                   set { SetValue(IsPasswordFlagProperty, value); }  
               }  
           }  
    

    Then Entry's custom renderer, you can judge it.

       [assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomEntryRendererAndroid))]  
       namespace RefreshViewDemo.Droid  
       {  
           public class CustomEntryRendererAndroid : EntryRenderer  
           {  
         
               protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)  
               {  
                   base.OnElementChanged(e);  
         
                   if (Control != null)  
                   {  
                       GradientDrawable gd = new GradientDrawable();  
         
                       gd.SetColor(Android.Graphics.Color.Transparent);  
                       this.Control.SetBackground(gd);  
                       this.Control.SetPadding(20, 0, 0, 0);  
                         
         
                       CustomEntry customEntry= (CustomEntry) e.NewElement ;  
                       if (customEntry.IsPasswordFlag)  
                       {  
                           this.Control.InputType = InputTypes.TextVariationVisiblePassword;  
                       }  
                        
                   }  
               }  
         
               public CustomEntryRendererAndroid(Context context) : base(context)  
               {  
         
               }  
           }  
    

    In the end, use it in xamarin,forms.

       <local:CustomEntry IsPasswordFlag="True"></local:CustomEntry>  
    

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.