Dan
Dan

Reputation: 1110

Focus entry ontop of keyboard

I am working on a Xamarin.Forms PCL app. I am trying to make it so users can comment on posts which displays as the post then scrolling down shows comments with a docked entry at the bottom of the page at all times

I tried

<ContentPage.Content>
    <StackLayout>
        <StackLayout>
            <ScrollView>
                <local:PostListView x:Name="Post">

                </local:PostListView>
                <StackLayout>
                    <ListView x:Name="CommentsList">
                    </ListView>
                </StackLayout>
            </ScrollView>
        </StackLayout>
        <StackLayout Padding="10, 5, 10, 10">
            <Entry Placeholder="Comment" BackgroundColor="GhostWhite"/>
            <StackLayout Orientation="Horizontal">
                <Button Text="Send" HeightRequest="20" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand" Margin="0, 0, 5, 0"/>
            </StackLayout>
        </StackLayout>
    </StackLayout>
</ContentPage.Content>

but when I click the entry it is covered by the keyboard, is it possible to make it sit above the keyboard?

Upvotes: 1

Views: 796

Answers (2)

Hichame Yessou
Hichame Yessou

Reputation: 2708

For Android you should set:

Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

and for iOS:

Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.iOS> ().UseWindowSoftInputModeAdjust (WindowSoftInputModeAdjust.Resize);

Upvotes: 1

ColeX
ColeX

Reputation: 14475

You can try KeyboardOverlap.

How it works?

1.Subscibe to keyboard Show/Dismiss events

2.On Keyboard Show

3.Find the Control, which activated the keyboard. (FirstResponder)

4.Determine if keyboard overlaps the Control

5.Calculate how far you need to shift the Page Up

6.Shift the Page Up

7.On Keyboard Dismiss

8.If Page was shifted up, shift the Page Down

Upvotes: 1

Related Questions