[英]How do I enable Copy/Paste/Select all menu in MaterialEditorRenderer Editor
我正在使用 Xamarin Forms 来呈现允许多行文本的编辑器。 但是,当我在编辑器框中长按已经有超过 1 行文本时,菜单不会显示以选择/剪切/复制文本。 如何启用此菜单? 如果它是单行文本,它就可以工作。
我已经将它设置为 true,所以它应该可以工作但不起作用。 Control.EditText.SetTextIsSelectable
这是我在 Android 项目中的代码。
[assembly: ExportRenderer(typeof(CustomEditor), typeof(CustomEditorRenderer))]
namespace MyProject.Droid.MRenderers
{
public class CustomEditorRenderer : MaterialEditorRenderer
{
public CustomEditorRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
Control?.SetBackgroundColor(Android.Graphics.Color.Transparent);
if (Control != null)
{
//This is the HeightRequest
var ElementHeightRequest = Element.HeightRequest;
//Convert it to Pixels
var EditTextHeight= ConvertToPixels(ElementHeightRequest);
//Set the Control's EditText height
Control.EditText.SetHeight(200);
Control.EditText.SetTextIsSelectable(true);
Control.EditText.Background = null;
Control.EditText.SetBackgroundColor(Android.Graphics.Color.Transparent);
}
}
您可以在渲染器中设置AutoSize
属性而不是SetHeight
。
自定义渲染器:
[assembly: ExportRenderer(typeof(CustomEditor), typeof(CustomEditorRenderer))]
namespace Test.Droid
{
public class CustomEditorRenderer : EditorRenderer
{
public CustomEditorRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Control.Background = null;
Control.SetPadding(0, 0, 0, 0);
Control.ShowSoftInputOnFocus = false;
Control.SetTextIsSelectable(true);
}
}
}
Xaml:
<local:CustomEditor AutoSize="TextChanges" Text="I am using Xamarin Forms to render an Editor that allows for multi-line text. However, when I long press in the Editor box when it already has more than 1 line of text, the menu is not showing up to select/cut/copy the text. How do I enable this menu? It works if it's a single line of text. I have already set this to true, so it should work but doesn't work."></local:CustomEditor>
您可以查看 output。 https://imgur.com/KcNtFH4
更新:
我没有对渲染器进行任何更改。 它可以在 MaterialEditorRenderer Editor 中显示 Copy/Paste/Select 菜单。
[assembly: ExportRenderer(typeof(CustomMaterialEditor),
typeof(CustomMaterialEditorRenderer))]
namespace Test3.Droid
{
public class CustomMaterialEditorRenderer : MaterialEditorRenderer
{
public CustomMaterialEditorRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Control.Background = null;
Control.SetPadding(0, 0, 0, 0);
//Control.DispatchSetSelected(true);
//Control.ShowSoftInputOnFocus = false;
//Control.SetTextIsSelectable(true);
}
}
}
Xaml:
<local:CustomMaterialEditor
AutoSize="TextChanges"
BackgroundColor="LightGray"
Text="I am using Xamarin Forms to render an Editor that allows for multi-line text. However, when I long press in the Editor box when it already has more than 1 line of text, the menu is not showing up to select/cut/copy the text. How do I enable this menu? It works if it's a single line of text. I have already set this to true, so it should work but doesn't work." />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.