如何在xamarin中打开对话框时暂停活动

时间:2016-06-01 08:18:37

标签: c# android xamarin visual-studio-2015 xamarin.android

我的动画上有一个动画,一个正在旋转的徽标......

我调用函数onBackPressed()显示警告对话框“你确定要退出吗?”有两个按钮“是”或“否”

.....我希望我的活动暂停,以便在对话框打开时徽标不会旋转...

这是我的代码

public override void OnBackPressed()
    {
        AlertDialog.Builder exit = new AlertDialog.Builder(this);
        exit.SetMessage("Are you sure You want to Exit");
        exit.SetCancelable(false);
        exit.SetPositiveButton("yes", (object sender, DialogClickEventArgs e) =>
         {
             this.Finish();
         });
        exit.SetNegativeButton("No", (object sender, DialogClickEventArgs e) =>
         {
         });
        exit.Show();}

2 个答案:

答案 0 :(得分:0)

保持对动画的引用,并在显示对话框时调用暂停:

public override void OnBackPressed()
{
    AlertDialog.Builder exit = new AlertDialog.Builder(this);
    exit.SetMessage("Are you sure You want to Exit");
    exit.SetCancelable(false);
    exit.SetPositiveButton("yes", (object sender, DialogClickEventArgs e) =>
     {
         this.Finish();
     });
    exit.SetNegativeButton("No", (object sender, DialogClickEventArgs e) =>
     {
       myAnimation.resume();
     });
    myAnimation.pause();
    exit.Show();
}

您可以使用这个好的示例/答案来了解如何暂停和恢复动画:https://stackoverflow.com/a/10028575/4706693 或者使用Animator课程中的简单暂停和继续,如果您正在使用

答案 1 :(得分:0)

can't暂停活动,但在您显示对话框时,系统会调用活动的lifecycle方法OnPause()

您只需stop/pause您的活动OnPause()方法中的MantisConnectPortTypeClient client = new MantisConnectPortTypeClient(); UserData usrData = client.mc_login("omitted", "omitted"); 动画。