locked
Is there a way to override a Back button press on Android And ios in Xamarin Forms? RRS feed

  • Question

  • User293254 posted

    OnBackButtonPressed only works for hardware back button for android devices but How to Working back button on the navigation bar ? Thanks for any help on this.

    Wednesday, December 20, 2017 6:02 AM

Answers

All replies

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, December 20, 2017 6:21 AM
  • User262242 posted

    @Charwaka

    I followed that example exactly the same to best of knowledge but get null for the toolbar:

     Android.Support.V7.Widget.Toolbar toolbar
                   = this.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
                SetSupportActionBar(toolbar);
    

    Do you have the same issue??

    Monday, April 16, 2018 10:40 PM
  • User76049 posted

    This should be implemented with an interface.

    Intercept the back press in the platform specific project Try and and cast to a known interface of the current page/view bindingcontext If it casts then call a method/invoke a handler to deal with it or let it fall through and let the page handle as it would by default.

    Monday, April 16, 2018 10:58 PM
  • User283999 posted

    @NMackay do you have an example of this? I have given it a shot but didn't get anywhere with the interface approach.

    Wednesday, October 3, 2018 7:41 PM
  • User76049 posted

    @RyanMendoza said: @NMackay do you have an example of this? I have given it a shot but didn't get anywhere with the interface approach.

    Post a repo of what you've tried, I'm rebuilding my home environment due to a disk failure so will take 2-3 days before can test code.

    Wednesday, October 3, 2018 10:50 PM
  • User283999 posted

    @NMackay I ended up getting this to work by sending a messaging using MessagingCenter to set the toolbar when the view that needs this is being rendered. Not a pretty fix, but it seems to work.

    Thursday, October 4, 2018 1:00 AM
  • User76049 posted

    @RyanMendoza

    Yeah, that will work, had to use that scenario once due to an app having no awaitable code in a navigation scenario I couldn't control. I'll pop up a sample with an interface approach.

    Thursday, October 4, 2018 8:28 AM
  • User369567 posted

    @RyanMendoza said: @NMackay do you have an example of this? I have given it a shot but didn't get anywhere with the interface approach.

    Would you mind sharing that code? Im facing the exact same problem and I think its a great solution!

    Monday, December 10, 2018 2:43 PM