XamarinForms AppCompat OnOptionsItemSelected [英] XamarinForms AppCompat OnOptionsItemSelected

查看:122
本文介绍了XamarinForms AppCompat OnOptionsItemSelected的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将xamarin表单更新为1.5.1-pre1,以便可以使用精美的AppCompat主题.它可以正常工作,而且看起来很好.

I have recently updated xamarin forms to 1.5.1-pre1 so that I can use the beautiful AppCompat themes. It works and looks very nice.

我确实有一个问题,在我以前的FormsApplicationActivity中,我重写了OnOptionsItemSelected方法,以在用户单击后退箭头图标并进行一些ViewModel清理时进行拦截.显然,在使用FormsAppCompatActivity之后不会调用此方法. 如何截获软"后退按钮(工具栏图标不是后退按钮)?

I do have one problem, in my old FormsApplicationActivity I used to override the OnOptionsItemSelected method to intercept when the user was clicking on the back arrow icon and do some viewmodel cleanup. Apparently this method is not being called after using the FormsAppCompatActivity. How can I intercept the "soft" back button press (toolbar icon not hard back button) ?

我还尝试覆盖Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer,但我似乎无法覆盖它:(

I also tried to override the Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer but i can't seem to override it :(

有人知道我该如何拦截吗?

Does anyone have a clue how I can intercept this?

推荐答案

添加OnOptionsItemSelected后,请按一下OnCreate()的最后两行.)

Have a look at the last two lines of the OnCreate() After adding them OnOptionsItemSelected was called as expected).

https://raw .githubusercontent.com/UdaraAlwis/Xamarin-Playground/master/XFNavBarBackBtnClickOverride/XFNavBarBackBtnClickOverride/XFNavBarBackBtnClickOverride.Droid/MainActivity.cs

        Toolbar toolbar = this.FindViewById<Toolbar>(Resource.Id.toolbar);

        SetSupportActionBar(toolbar);

这篇关于XamarinForms AppCompat OnOptionsItemSelected的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆