我的 mypage.xaml 文件中有一个编辑器字段在 Xamarin、forms 项目中 。当我尝试在字段中插入某些内容时,光标变成紫色,这与我的应用程序的样式和颜色完全不同。文本选择的颜色也是紫色。如何在我的 Android 项目中更改它?
您可以为此问题创建编辑器的自定义渲染器。
步骤1。在 XamarinProject.Android 中创建 MyEditor.cs 类。
[assembly: ExportRenderer(typeof(Eitor), typeof(MyEditor))]
namespace App38.Droid
{
class MyEntry : EditorRenderer
{
public MyEntry(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
EditText nativeEditText = (global::Android.Widget.EditText)Control;
nativeEditText.SetTextCursorDrawable(Resource.Drawable.CursorFile);
}
}
}
}
步骤 2. 在 XamarinProject.Android -> Resource -> 使用
xml
文件创建 CursorFile。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<!-- edit text cursor width 2 dp -->
<size android:width="2dp"/>
<!-- edit text cursor color red -->
<solid android:color="#00ff00"/>
</shape>
</item>
</selector>
这是运行截图。