0

The page has no input fields(only one label), but the keyboard does not disappear when you switch to this page. Is this normal behavior? How to make the keyboard not open on a new page? thank

First page xaml

<ContentPage.Content>
    <StackLayout x:Name="stackLayout2">
        <Label x:Name="code_label" HorizontalOptions="CenterAndExpand" Font="Bold, Micro" TextColor="black" FontSize="19" Margin="15, 30, 15, 0" />
        <Entry x:Name="code_field" TextChanged="CodeFieldTextChanged"  Keyboard="Telephone" MaxLength="4" Margin="15, 30, 15, 0" />
    </StackLayout>
</ContentPage.Content>

First page CodeFieldTextChanged method

private void CodeFieldTextChanged(object sender, TextChangedEventArgs args)
{
    if (args.NewTextValue == "3333")
    {
        Application.Current.MainPage = new HomePage();
    }
}

HomePage xaml

<ContentPage.Content>
    <StackLayout>
        <Label Text="Authorization ok!"
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage.Content>

If Application.Current.MainPage = new HomePage(); is replaсed by Application.Current.MainPage = new NavigationPage(new HomePage()); then keyboard disappears, but in the first case keyboard stays

2
  • 1
    Can you supply a MCVE (minimal, complete, verifiable example? stackoverflow.com/help/mcve Commented Oct 30, 2018 at 23:53
  • I added code samples Commented Oct 31, 2018 at 0:26

1 Answer 1

1

This issue only seems to occur on Android. And what is happening is that you are changing the page without ever hitting "Return" (green Check mark on the Telephone keyboard) so the keyboard does not get dismissed by the OS, so you have to dismiss it manually. Try this:

private void CodeFieldTextChanged(object sender, TextChangedEventArgs args)
{
    if (args.NewTextValue == "3333")
    {
        // Add the following two lines to dismiss the keyboard
        Entry entry = sender as Entry;
        entry.Unfocus();
        Application.Current.MainPage = new HomePage();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.