Reputation: 318
I want to make a entry that without underline. I tried two solutions but both can not work well.
Control.Background = null;
it is not go well and I take another solution:
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));
It also not go well in android but work well in ios.I do not understand why.
Upvotes: 0
Views: 105
Reputation: 71
Try my implementation(working for Android and ios). PlainEntry is empty class inherited from Xamarin.Forms.Entry
Android
[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);
}
}
}
}
If you want to use renderers for all Xamarin.Forms.Entry like not the than specify:
[assembly: ExportRenderer(typeof(Xamarin.Forms.Entry), typeof(PlainEntryRenderer))]
Upvotes: 0
Reputation: 1611
You can try add xml styling named editText_bg.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>
And you can give this to entry as background resource :
[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);
}
}
}
}
Upvotes: 1