Xamarin Forms Android Keyboard moves entire page up

I tried to write a Xamarin.Forms chat application. Problem: On Android, as soon as the keyboard displays the entire page (including the ActionBar), it moves up. I can fix the problem on iOS using the NuGet package, which resizes the page.

I have already tried setting WindowSoftInputMode = Android.Views.SoftInput.AdjustResize to MainActivity.cs in an Android project, but this did not work. I also tried changing the page size manually by recounting the screen size, but I did not find a solution to get the keyboard size for accurate calculation on different devices.

Has anyone had the same problem before? Is there an official Xamarin.Forms solution for all supported platforms?

This is my chat layout:

 <ContentPage.Content> <StackLayout Padding="0"> <ScrollView> <ListView HasUnevenRows="true" x:Name="lvChat" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill" Padding="5"> <Label Text="{Binding Author, StringFormat='{0}: '}" TextColor="Navy" FontSize="14" /> <Label Text="{Binding Text}" TextColor="Black" FontSize="15" /> <Label Text="{Binding Time}" TextColor="Black" FontSize="14" /> <!-- Format for time.. , StringFormat='{0:HH:mm}' --> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </ScrollView> <StackLayout Orientation="Horizontal" Padding="0" Margin="5, 5, 5, 5"> <Entry Keyboard="Chat" x:Name="tbxChatInput" HorizontalOptions="FillAndExpand" Placeholder="Send a Message..." /> <Button x:Name="btnSendMsg" HorizontalOptions="End" Text="Send" Margin="5"/> </StackLayout> </StackLayout> 

Thanks in advance!

+5
source share
2 answers

Hi, try putting a stacklayout that contains your enter and send button inside a scrollview, so when you click on the input that it clicks on the keyboard, you see your input, and the rest of your chat works fine on both iOS and Android Try the following:

  <ContentPage.Content> <StackLayout Padding="0"> <ScrollView> <StackLayout> <ListView HasUnevenRows="true" x:Name="lvChat" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill" Padding="5"> <Label Text="{Binding Author, StringFormat='{0}: '}" TextColor="Navy" FontSize="14" /> <Label Text="{Binding Text}" TextColor="Black" FontSize="15" /> <Label Text="{Binding Time}" TextColor="Black" FontSize="14" /> <!-- Format for time.. , StringFormat='{0:HH:mm}' --> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <StackLayout Orientation="Horizontal" Padding="0" Margin="5, 5, 5, 5"> <Entry Keyboard="Chat" x:Name="tbxChatInput" HorizontalOptions="FillAndExpand" Placeholder="Send a Message..." /> <Button x:Name="btnSendMsg" HorizontalOptions="End" Text="Send" Margin="5"/> </StackLayout> </StackLayout> </ScrollView> </StackLayout> </ContentPage.Content> 
+1
source

Try installing windowSoftInputMode in your Android manifest, for example:

 <application ... > <activity android:windowSoftInputMode="adjustResize" ... > ... </activity> ... </application> 
0
source

Source: https://habr.com/ru/post/1264940/


All Articles