Abhirup Ghosh
Abhirup Ghosh

Reputation: 135

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?

Upvotes: 4

Views: 3420

Answers (1)

Srusti Thakkar
Srusti Thakkar

Reputation: 1911

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.

Upvotes: 3

Related Questions