DrawerOpened事件处理程序是在Monodroid中调用的注释

时间:2013-06-12 08:25:20

标签: xamarin.android

我在Monodroid中使用DrawerLayout小部件,从本教程http://developer.android.com/training/implementing-navigation/nav-drawer.html移植。

抽屉工作正常,但是当抽屉打开或关闭时,永远不会调用DrawerOpened和DrawerClosed事件处理程序。我使用小部件中的内置监听器。抽屉布局放在片段中。

有什么想法吗?非常感谢帮助。

this.DrawerLayout.DrawerClosed += delegate(object sender,   Android.Support.V4.Widget.DrawerLayout.DrawerClosedEventArgs e)
        {
            this.Activity.ActionBar.SetTitle(Resource.String.ApplicationName);
            this.Activity.InvalidateOptionsMenu();
        };

            this.DrawerLayout.DrawerOpened += delegate(object sender, Android.Support.V4.Widget.DrawerLayout.DrawerOpenedEventArgs e)
        {
            this.Activity.ActionBar.SetTitle(this.Title);
            this.Activity.InvalidateOptionsMenu();
        };

        this.DrawerLayout.SetDrawerListener(this.DrawerToggle);

1 个答案:

答案 0 :(得分:0)

我自己刚遇到这个问题。我相信如果您在设置Drawer Opened和Closed事件的委托之前设置抽屉监听器,则会触发此事件。

所以只需将代码更改为:

this.DrawerLayout.SetDrawerListener(this.DrawerToggle);

this.DrawerLayout.DrawerClosed += delegate(object sender,   Android.Support.V4.Widget.DrawerLayout.DrawerClosedEventArgs e)
        {
            this.Activity.ActionBar.SetTitle(Resource.String.ApplicationName);
            this.Activity.InvalidateOptionsMenu();
        };

            this.DrawerLayout.DrawerOpened += delegate(object sender, Android.Support.V4.Widget.DrawerLayout.DrawerOpenedEventArgs e)
        {
            this.Activity.ActionBar.SetTitle(this.Title);
            this.Activity.InvalidateOptionsMenu();
        };

这似乎对我有用。