如何使加载符号保持活动状态,直到页面加载完成。ProgressDialog加载符号在xamarin本机android停止后,页面才会出现

问题描述 投票:0回答:1

ProgressDialog加载符号停止后,我的页面稍后加载。在我的页面图像列表视图内部,正在通过GetImageBitmapFromUrl加载。您能否建议我如何继续加载登录,直到页面正确加载。...

 public override async void OnActivityCreated(Bundle savedInstanceState)
    {
        base.OnActivityCreated(savedInstanceState);

        var mDialog = new ProgressDialog(this.Context);
        mDialog.SetMessage("Please wait...");
        mDialog.SetCancelable(false);
        mDialog.Show();


        _data = (await ServiceContext.Current.Duas.GetAll()).ToList();
        DuasAdapter adapter = new DuasAdapter(this.Context, _data);
        _lstDuas.Adapter = adapter;

        _lstDuas.ItemClick += LstDuas_ItemClick;

        mDialog.Cancel();
    }
xamarin.android
1个回答
0
投票

如何在Android平台上使用Splash Screen处理一些任务,

Android应用程序需要花费一些时间才能启动,尤其是在设备上首次启动该应用程序时。启动屏幕可能会向用户显示启动进度或指示品牌。

您可以创建一个启动画面以显示ProgressDialog或其他动画。等待一会儿后,关闭Dialog或完成Animation并进入MainActivity

[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
    static readonly string TAG = "X:" + typeof (SplashActivity).Name;
    Android.App.AlertDialog alert;
    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        base.OnCreate(savedInstanceState, persistentState);
        Log.Debug(TAG, "SplashActivity.OnCreate");


    }

    // Launches the startup task
    protected override void OnResume()
    {
        base.OnResume();
        Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
        alert = dialog.Create();
        alert.Show();
        Task startupWork = new Task(() => { SimulateStartup(); });
        startupWork.Start();
    }

    // Prevent the back button from canceling the startup process
    public override void OnBackPressed() { }

    // Simulates background work that happens behind the splash screen
    async void SimulateStartup ()
    {
        Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
        await Task.Delay(8000); // Simulate a bit of startup work.
        Log.Debug(TAG, "Startup work is finished - starting MainActivity.");
        alert.Cancel();
        StartActivity(new Intent(Application.Context, typeof (MainActivity)));
    }
}

效果:

enter image description here

文档中有一个sample,您可以看一下。

© www.soinside.com 2019 - 2024. All rights reserved.