如何获得对ActionBarDrawerToggle的引用?

时间:2019-05-16 20:03:44

标签: android xamarin.forms android-appcompat

我有一个Xamarin Forms应用程序,该应用程序从FormsActivity移植到AppCompatActivity。对于功能要求,应该始终显示汉堡图标,这是我使用

完成的操作
NavigationPage.SetHasBackButton(nextPage, false);

但这不适用于AppCompat,并且问题报告已经解决了一年多,因此,我尝试使用自定义渲染器解决问题。我可以成功创建并显示该图标,但是点击它不会显示正确的行为。我在想我需要做的是将DrawerIndicatorEnabled设置为true并调用SyncState,但是我需要对ActionBarDrawerToggle的引用才能做到这一点,但我还没有弄清楚如何获取它。

编辑:这是带有屏幕截图的错误报告: https://github.com/xamarin/Xamarin.Forms/issues/2577

这是自定义的NavigationPageRenderer:

[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationPageRenderer))] 

namespace HeaderTest.Droid
{
    public class CustomNavigationPageRenderer : NavigationPageRenderer // APPCOMP
    {
        public CustomNavigationPageRenderer(Context context) : base(context)
        {
        }

        protected override Task<bool> OnPushAsync(Page view, bool animated)
        {
            var retVal = base.OnPushAsync(view, false);

            var context = (Activity)Context;
            var toolbar = context.FindViewById<AToolbar>(Resource.Id.toolbar);

            if (toolbar != null)
            {
                var icon = new DrawerArrowDrawable(context)
                {
                    SpinEnabled = false,
                };
                toolbar.NavigationIcon = icon;
            }

            return retVal;
        }
    }
}

0 个答案:

没有答案