是否可以更改下面的线的颜色/TextBox的边框(条目) [英] Is it possible to change the colour of the line below / Border of a TextBox (Entry)
问题描述
我正在Android
上创建一个Xamarin.Forms
应用程序,并且试图更改Xamarin.Forms
Entry
控件下方的行的颜色.
I am creating a Xamarin.Forms
application on Android
and I am trying to change the colour of the line below my Xamarin.Forms
Entry
control.
我有一个Entry
控件,如下所示:
I have an Entry
control like so:
<Entry Text="new cool street"/>
我想将此Entry
下面的线的颜色从默认的白色更改为更多的紫色,以匹配我的主题.
I would like to change the colour of the line below this Entry
from the default white to more of a purple to match my theme.
最好使用Android样式,因为如果可能的话,它将应用于所有从Entry
继承的控件
Idealy it would be better to do using Android Styles as it would apply to all controls inheriting from Entry
if possible
这可能吗?
推荐答案
您可以使用将影响所有条目的自定义渲染器,
you can use custom renderer that will affect all entries,
这是针对android:
here's for android:
[assembly: ExportRenderer(typeof(Entry), typeof(MyEntryRenderer))]
namespace Android.MyRenderers
{
public class MyEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null || e.NewElement == null) return;
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
Control.BackgroundTintList = ColorStateList.ValueOf(Color.White);
else
Control.Background.SetColorFilter(Color.White, PorterDuff.Mode.SrcAtop);
}
}
}
和iOS:
[assembly: ExportRenderer (typeof(Entry), typeof(MyEntryRenderer))]
namespace iOS.MyRenderers
{
public class MyEntryRenderer : EntryRenderer
{
private CALayer _line;
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged (e);
_line = null;
if (Control == null || e.NewElement == null)
return;
Control.BorderStyle = UITextBorderStyle.None;
_line = new CALayer {
BorderColor = UIColor.FromRGB(174, 174, 174).CGColor,
BackgroundColor = UIColor.FromRGB(174, 174, 174).CGColor,
Frame = new CGRect (0, Frame.Height / 2, Frame.Width * 2, 1f)
};
Control.Layer.AddSublayer (_line);
}
}
}
不确定与此有关的Windows解决方案
not sure about Windows solution on this
这篇关于是否可以更改下面的线的颜色/TextBox的边框(条目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!