MonoDroid闪屏 [英] MonoDroid Splash Screen

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

问题描述

我怎么能实现在程序启动一个简单的闪屏?我复制一个SQLite数据库,它可以是一个有点漫长的过程,是不是用户界面友好。

How can I implement a simple "splash screen" on program startup? I am copying a SQLite DB and it can be a bit of a long process that is not UI "friendly" .

我会preFER不使用的java code。

I would prefer not to use "java code".

TIA

推荐答案

我最近在下面的方式解决了这个问题。

I recently solved this problem in the following way.

在主要活动通过我的意图传递一个参数来设置毫秒为其开机画面将保持可见数量。

In the main activity I passed a parameter via the intent to set the number of milliseconds for which the splash screen would remain visible.

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        Intent i=new Intent();
        i.SetClass(this, typeof (Splash));
        i.PutExtra("Milliseconds", 3000);
        StartActivity(i);
    }

然后,我在其中一个名为泼水节的第二个活动我检索到的值,并设置第二个线程结束活动时,时间已经过去了。

Then, in the second activity which I named "Splash" I retrieved the value and set a second thread to end the activity when the time had elapsed.

[Activity(Label = "Daraize Tech")]
public class Splash : Activity
{
    private int _milliseconds;
    private DateTime _dt;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        _milliseconds = Intent.GetIntExtra("Milliseconds", 1000);
        SetContentView(Resource.Layout.Splash);
        _dt=DateTime.Now.AddMilliseconds(_milliseconds);
     }

    public override void OnAttachedToWindow()
    {
        base.OnAttachedToWindow();

        new Thread(new ThreadStart(() =>
                                    {
                                    while (DateTime.Now < _dt)
                                        Thread.Sleep(10);
                                    RunOnUiThread( Finish );                                                   
                                    }
            )).Start();
    }

}

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

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