View scroll when keyboard open for typing in Entry Control

3k views Asked by At

when user focus Entry Control in Xamarin.Form keyboard open but view scroll so Design looks ugly.so please help me. i have put image how screen visible when keyboard open in android device. My code given below

<StackLayout Grid.Row="1">
        <StackLayout Padding="20,10,20,20" >
            <Entry x:Name="Txtusername" Placeholder="Name"/>
            <Entry x:Name="TxtPass"
                   IsPassword="True"
                   Placeholder="Password" />
            <StackLayout Padding="0,10">
                <Button x:Name="BtnSign"
                        BackgroundColor="#FFFFCB04"
                        BorderColor="#FFFFCB04"
                        Clicked="BtnSignInClicked"
                        Text="Sign In"
                        TextColor="Black" />
            </StackLayout>
        </StackLayout>
    </StackLayout>

Before keyboard open

After keyboard open

1

There are 1 answers

0
Akash Amin On

Add WindowSoftInputMode=SoftInput.AdjustPan in your [Activity()] on top of your MainActivity class from where the FormsApplication start.

This is so that your layout does not change when keyboard is active. I think you won't need scroll here. If you want scroll then add scroll view in your code

<ScrollView>
.//your grid 
.
    <StackLayout Grid.Row="1">
        <StackLayout Padding="20,10,20,20" >
            <Entry x:Name="Txtusername" Placeholder="Name"/>
            <Entry x:Name="TxtPass"
                   IsPassword="True"
                   Placeholder="Password" />
            <StackLayout Padding="0,10">
                <Button x:Name="BtnSign"
                        BackgroundColor="#FFFFCB04"
                        BorderColor="#FFFFCB04"
                        Clicked="BtnSignInClicked"
                        Text="Sign In"
                        TextColor="Black" />
            </StackLayout>
        </StackLayout>
    </StackLayout>
</ScrollView>