简体   繁体   中英

Xamarin Android long press back button

I need advice. I'm trying to create an event by long pressing the back button. I found this code: https://stackoverflow.com/a/65031537/6473719 which is in kotlin and I have a little problem converting it to C # specifically I have a problem with this event:

private fun handleBackLongPress(): Boolean {
supportFragmentManager.primaryNavigationFragment?.childFragmentManager?.fragments?.forEach {
    if (it is OnBackLongPressedListener && it.onBackLongPressed()) {
        return true
    }
}
return false
}

would anyone know how to convert this to C #.

Xamarin Android long press back button

If you want to listen for the long back event in android, you can override method OnKeyLongPress in your activity:

      public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent e)
    {
        if (keyCode == Keycode.Back)
        {
            System.Diagnostics.Debug.WriteLine("------------->Back button long pressed ");
            return true;
        }
        return base.OnKeyLongPress(keyCode, e);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM