Enable MaterialEditorRenderer (Copy, Cut and Selection) of Multiline Text

Tasi Mals 1 Reputation point
2021-02-10T17:51:44.837+00:00

Hello,

I am using Xamarin Forms to render an Editor that allows for multiline 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. Control.EditText.SetTextIsSelectable

This is the code I have in the Android Project.

[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);
            }
        }
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,315 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-02-11T02:50:55.667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Test on Xamarin.Forms 5.x , it works fine , the edit menu shows up as expected .

    66781-capture.png

    Could you also provide the code in forms project(xaml and code behind) ?


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments