Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin form Keyboard overlapping Entry field

I want to scroll the page when the keyboard is opened. Right now the keyboard is covering my other entry fields. I have tried the soft input method. But it's not working in xamarin form.

What should I do?

like image 613
Abhirup Ghosh Avatar asked Oct 12 '25 04:10

Abhirup Ghosh


1 Answers

you have to add manually translation on entry focus. Try below code in constructor:

 this.entryname.Focused += (s, e) => { SetLayoutPosition(onFocus: true); };
 this.entryname.Unfocused += (s, e) => { SetLayoutPosition(onFocus: false); };

Then after just paste below method :

void SetLayoutPosition(bool onFocus)
    {
        if (onFocus)
        {
            if (Device.RuntimePlatform == Device.iOS)
            {
                this.CenteredStackLayout.TranslateTo(0, -100, 50);
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                this.CenteredStackLayout.TranslateTo(0, -100, 50);
            }
        }
        else
        {
            if (Device.RuntimePlatform == Device.iOS)
            {
                this.CenteredStackLayout.TranslateTo(0, 0, 50);
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                this.CenteredStackLayout.TranslateTo(0, 0, 50);
            }
        }
    }

You can change "50" to any value according to your requirement.

like image 90
Srusti Thakkar Avatar answered Oct 15 '25 16:10

Srusti Thakkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!