Home > Blockchain >  Custom Popup designed with Content View Closing Issue on Hardware Click in Android Xamarin forms
Custom Popup designed with Content View Closing Issue on Hardware Click in Android Xamarin forms

Time:06-29

We have designed a custom popup with Content View, which will be invoked in a content page. When clicked on hardware back custom popup is getting closed, because Content View as no property to hand hardware back button Pressed. OnBackButtonPressed() is used only for Content Page. Can I get any solution to handle hardware back for content view to stop popup from closing.

CodePudding user response:

Set the flag on Contentpage when you open popup make the bool as true.

bool isShowPopup = false;

public override void OnBackPressed() { if (!isShowPopup) { base.OnBackPressed(); } }

CodePudding user response:

To manage hardware back button you must override OnBackPressed() method in MainActivity class, in android project. In your popup you may have some property to check if can be closed and then check it from MainActivity class.

public override void OnBackPressed()
{
    if (CheckIfCanBePressedMethod())
    {
        // back pressed will be ignored
        // code here
    }
    else 
    {
        // default behavior
        base.OnBackPressed();
    }
}
  • Related