Move caret to start of placeholder when in center Entry Xamarin

190 views Asked by At

I use text alignment in Entry. When I touch entry, the caret appears in the middle of the placeholder, which looks ugly.

I want to move the caret to the start placeholder. And when i enter text in the center.

enter image description here

1

There are 1 answers

0
Lucas Zhang On

I afraid that it is impossible to set the the index of cursor when the entry first load . As a workaround , you could set the HorizontalTextAlignment="Start" and set the padding of the entry by using custom renderer.

using Android.Content;

using App24;
using App24.Droid;

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;


[assembly:ExportRenderer(typeof(Entry),typeof(MyEntryRenderer))]
namespace App24.Droid
{
    public class MyEntryRenderer: EntryRenderer
    {
        public MyEntryRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if(Control!=null)
            {
                Control.SetPadding(100,0,100,0);  // set the padding left and right here 
            }

        }
    }
}