简体   繁体   English

如何使 Android 应用程序加载到徽标中然后返回主要活动?

[英]How to make the Android app load into logo then back to main activity?

I am new to App Development and I've been studying Kotlin for only a month now (1 hour everyday).我是应用程序开发的新手,我学习 Kotlin 仅一个月(每天 1 小时)。 I got the grasp of the functions but I still haven't gotten around using them for the purposes I have in mind.我掌握了这些功能,但我仍然没有将它们用于我想要的目的。

Using Android Studio, I am trying to make the App load into a logo upon opening the app(Just like Facebook, Reddit), the logo is animated (which is not a problem for me).使用 Android Studio,我试图在打开应用程序时将应用程序加载到徽标中(就像 Facebook,Reddit 一样),徽标是动画的(这对我来说不是问题)。 I have a couple of ways to achieve this but I wanna see what's the most efficient way to do it.我有几种方法可以实现这一目标,但我想看看最有效的方法是什么。

Create a new SplashActivity and change your starting activity in you manifest file like this:创建一个新的 SplashActivity 并在清单文件中更改您的起始活动,如下所示:

<activity
    android:name=".SplashActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

then in your SplashActivity's OnCreate, start your MainActivity然后在你的 SplashActivity 的 OnCreate 中,启动你的 MainActivity

startActivity(Intent(this, MainActivity::class.java))

You can read more about this here .您可以在此处阅读有关此内容的更多信息。

You can create one Activity let's say SplashActivity which will have your logo and animations you want.您可以创建一个Activity ,比如说SplashActivity ,它将拥有您想要的徽标和动画。 Then from that Activity you can start your MainActivity .然后从那个Activity你可以开始你的MainActivity If you need to process some data inside your SplashActivity you do that then you start MainActivity .如果您需要在SplashActivity中处理一些数据,那么您可以启动MainActivity Otherwise, if you don't have any data to process you can simply start MainActivity with some delay, like this:否则,如果您没有任何数据要处理,您可以简单地延迟启动MainActivity ,如下所示:

 Handler().postDelayed({
            val i = Intent(this, MainActivity::class.java)
            startActivity(i)
        }, 5000)

This will start your MainActivity after 5000 milliseconds which is 5 seconds.这将在 5000 毫秒(即 5 秒)后启动您的MainActivity Now try to write some code and if you run into a problem try to find a solution or ask again if you can't.现在尝试编写一些代码,如果遇到问题,请尝试找到解决方案或再次询问是否无法解决。 There is a lot of tutorials on the Internet you can find on how to do this.互联网上有很多关于如何做到这一点的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM