C# 如何在xamarin crossplatform中更改编辑器底边线颜色

C# 如何在xamarin crossplatform中更改编辑器底边线颜色,c#,xamarin.forms,xamarin.android,C#,Xamarin.forms,Xamarin.android,这是我的渲染器代码 public class CustomEditorControlRenderer: EditorRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Editor> e) { base.OnElementChanged(e); if (e.NewElement != null) {

这是我的渲染器代码

public  class CustomEditorControlRenderer: EditorRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
    {
        base.OnElementChanged(e);

        if (e.NewElement != null)
        {
            var _element = e.NewElement as EditorControl;

            this.Control.Hint = _element.Placeholder;

            Control.SetHintTextColor(_element.PlaceholderColor.ToAndroid());
            this.Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
            this.Control.SetCursorVisible(true);              

            Control.Background.SetColorFilter(Android.Graphics.Color.White, PorterDuff.Mode.SrcAtop);

        }

      }       

    }
公共类CustomEditorControlRenderer:EditorRenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(例如NewElement!=null)
{
var_element=e.NewElement作为编辑器控件;
this.Control.Hint=\u element.Placeholder;
Control.SetHintTextColor(_element.PlaceholderColor.ToAndroid());
this.Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
this.Control.SetCursorVisible(true);
Control.Background.SetColorFilter(Android.Graphics.Color.White,PorterDuff.Mode.SrcAtop);
}
}       
}

Control.Background.SetColorFilter(Android.Graphics.Color.White,PorterDuff.Mode.SrcAtop)不起作用

我认为您不需要渲染器,用填充将编辑器包装到StackLayout中如何? 这应该可以做到:

<StackLayout BackgroundColor="White">
      <StackLayout BackgroundColor="Black" Padding="1">
          <Editor BackgroundColor="White" />
      </StackLayout>
</StackLayout>

您可以使用
选择器来实现:

C#代码
et\u underline\u unselected.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_focused="false" android:drawable="@drawable/et_underline_unselected"/>
  <item android:state_focused="true" android:drawable="@drawable/et_underline_selected"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item
      android:bottom="0dp"
      android:left="-2dp"
      android:right="-2dp"
      android:top="-2dp">
    <shape>
      <solid android:color="@android:color/transparent" />
      <stroke
          android:width="1dp"
          android:color="@android:color/darker_gray" />
      <padding android:bottom="4dp" />
    </shape>
  </item>

</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

  <item
      android:bottom="0dp"
      android:left="-2dp"
      android:right="-2dp"
      android:top="-2dp">
    <shape>
      <solid android:color="@android:color/transparent" />
      <stroke
          android:color="@android:color/holo_green_light"
          android:width="2dp" />
      <padding android:bottom="4dp" />

    </shape>
  </item>

</layer-list>
我用“et_underline_unselected.xml”代码解决了我的问题,并做了一些修改。谢谢!!!
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

  <item
      android:bottom="0dp"
      android:left="-2dp"
      android:right="-2dp"
      android:top="-2dp">
    <shape>
      <solid android:color="@android:color/transparent" />
      <stroke
          android:color="@android:color/holo_green_light"
          android:width="2dp" />
      <padding android:bottom="4dp" />

    </shape>
  </item>

</layer-list>