1

I have a simple File->New Project Xamarin Forms app just created. When the Editor gains focus the navigation bar slides up. Is this a bug, or how do you lock the navigation bar in place and scroll the page content instead?

Runnable source code can be download here. I am observing this behavior on a Samsung Note 3 phone. This doesn't happen in iOS.

https://github.com/JohnLivermore/SampleXamarinApp/tree/funkyNavbar

App.xaml

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        var mainPage = new MainPage();
        var nav = new NavigationPage(mainPage);

        MainPage = nav;
    }
}

MainPage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             Title="Page Title"
             x:Class="SampleApp.MainPage">
    <ScrollView>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Text="Field A:" />
            <Editor Grid.Row="1" HeightRequest="200" />
            <Label Grid.Row="2" Text="Field B:" />
            <Editor Grid.Row="3" HeightRequest="200" />
            <Label  Grid.Row="4" Text="Field B:" />
            <Editor Grid.Row="5" HeightRequest="200" />
            <Label  Grid.Row="6" Text="Field B:" />
            <Editor Grid.Row="7" HeightRequest="200" />
            <Label  Grid.Row="8" Text="Field B:" />
            <Editor Grid.Row="9" HeightRequest="200" />
        </Grid>
    </ScrollView>
</ContentPage>
Cfun
  • 8,442
  • 4
  • 30
  • 62
John Livermore
  • 30,235
  • 44
  • 126
  • 216

2 Answers2

1

Add the following code in App.cs to make page auto-resizable.

using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
public partial class App : Xamarin.Forms.Application
{
    public App()
    {
        Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
        InitializeComponent();
        MainPage = new NavigationPage(new MainPage());
    }
}
Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
  • Thanks. That worked. I am showing the keyboard on a modal page. If I click into an entry the keyboard shows and the navbar doesn't scroll. All is great. Then when I dismiss the dialog, the keyboard remains. How do I force the keyboard to hide? Or is the answer complex enough that I need a new question? If I touch a label on the form, the keyboard hides. But if I touch the navbar it doesn't. I have seen a potential solution using a custom renderer, but I want to see if their is a XF solution first. – John Livermore Oct 11 '19 at 13:08
0

If you want to make the toolbar's position static in Android, try adding this in [Activity] attribute in your MainActivity:

WindowSoftInputMode = Android.Views.SoftInput.AdjustNothing

More info here.

Dustin Catap
  • 411
  • 5
  • 11