0
votes

How to handle hardware back button pressed while keyboard is open in Xamarin Forms?The OnBackPressed event does not fire if the keyboard is open.Is there any way I can track the hardware back button click while the keyboard is open?

1
But the back button will close the keyboard, won't it? And once it is closed, the next click on the back button should fire OnBackPressed. That's how it is supposed to work on the platform.Thomas Hilbert
Yes.But in my app I have an entry field with keyboard open when im typing.After clicking the hardware back button I want to force the entry field to loose focus.So i wanted to track that event. @ThomasHilbertDebasish

1 Answers

0
votes

After clicking the hardware back button I want to force the entry field to loose focus.

You could override the OnBackButtonPressed method to track the hardware back button click, it did work even if your keyboard is open.

For example :

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    protected override bool OnBackButtonPressed()
    {
        if (myEntry.IsFocused)
        {
            myEntry.Unfocus();
        }
        return base.OnBackButtonPressed();
    }

}

Effect.