启动/加载时的图像

发布于 2024-11-16 04:52:57 字数 126 浏览 3 评论 0原文

我正在开发一个应用程序,当它从 onCreate 点加载时,我只是有一个黑屏(直到应用程序站稳脚跟)。看看其他应用程序,他们有公司徽标或很酷的图像,会弹出几秒钟,有人可以告诉我该怎么做吗?

是否可以将其设置为最短显示时间?

I ma developing an app, which at the moment when it is loading from the onCreate point, I just have a black screen (until the app gets its footing). Looking at other apps they have a company logo or cool image that pops up for a few seconds, can someone tell me how to do this please?

And if you can set it to display for a minimal time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静水深流 2024-11-23 04:52:57

创建一个新活动,将图像显示几秒钟并重定向到您的主要活动:

public class SplashActivity extends Activity
{
    private static final long DELAY = 3000;
    private boolean scheduled = false;
    private Timer splashTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        splashTimer = new Timer();
        splashTimer.schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                SplashActivity.this.finish();
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            }
         }, DELAY);
       scheduled = true;
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if (scheduled)
            splashTimer.cancel();
        splashTimer.purge();
    }
}

将您的图像设置为该活动的背景。希望有帮助。祝你好运!

Create a new activity that displays the image for a few seconds and redirects to your main activity:

public class SplashActivity extends Activity
{
    private static final long DELAY = 3000;
    private boolean scheduled = false;
    private Timer splashTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        splashTimer = new Timer();
        splashTimer.schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                SplashActivity.this.finish();
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            }
         }, DELAY);
       scheduled = true;
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if (scheduled)
            splashTimer.cancel();
        splashTimer.purge();
    }
}

Set your image as the background for this activity. Hope that helps. Good luck!

疯狂的代价 2024-11-23 04:52:57

该启动图像也称为“启动画面”。 在这里您可以找到如何制作闪屏。

This start up image also known as 'splash screen'. Here you can find how to make splash screen.

月隐月明月朦胧 2024-11-23 04:52:57

您的需求是启动画面。这是我的启动画面代码。

只需添加新活动并设置打开该活动的应用程序即可。

public class SplashActivity extends DeviceInfoAbstractActivity {

@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.activity_splash);

    passScreen();
}

private void passScreen() {

    new CountDownTimer(1000, 2000) {

        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {

            Intent intent = RDAIntentHelpers.getClearCacheIntent();

            intent.setClass(SplashActivity.this, MainActivity.class);

            startActivity(intent);

        }
    }.start();
}

@Override
public void onBackPressed() {
    //no exit
}
}

这是我的 getClearCacheIntent() 方法

public static Intent getClearCacheIntent() {

    Intent intent = new Intent();

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    return intent;
}

在这些之后,您的启动屏幕将在屏幕上停留 2 秒钟。做你想做的事 =)

Your needs is callign Splash Screen. Here is my splash screen code.

Just add new activity and set application for opening this activity.

public class SplashActivity extends DeviceInfoAbstractActivity {

@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.activity_splash);

    passScreen();
}

private void passScreen() {

    new CountDownTimer(1000, 2000) {

        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {

            Intent intent = RDAIntentHelpers.getClearCacheIntent();

            intent.setClass(SplashActivity.this, MainActivity.class);

            startActivity(intent);

        }
    }.start();
}

@Override
public void onBackPressed() {
    //no exit
}
}

and this my getClearCacheIntent() method

public static Intent getClearCacheIntent() {

    Intent intent = new Intent();

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    return intent;
}

after these, your splash screen stays on screen for 2 seconds. Do whatever you want =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文