如何集成启动画面活动和应用程序

时间:2017-07-28 15:40:26

标签: java android

我为我的学校项目制作了一个应用程序,我想知道如何将两个东西整合在一起?带有应用程序的启动画面。

2 个答案:

答案 0 :(得分:1)

像这样创建你的Splash屏幕活动来实现它

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity {

// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;

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

    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
// replace SPLASH_TIME_OUT with your amount of milliseconds
}

}

答案 1 :(得分:0)

创建启动画面正确方式正在这样做:

1)创建一个名为 splashscreen drawable 文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item android:drawable="@android:color/white"/>

    <item
        android:top="80dp"
        android:bottom="80dp">

        <bitmap
            android:gravity="fill"
            android:src="@drawable/logo"/>

    </item>

</layer-list>

2)将此可绘制文件添加为主要活动背景,并创建一个主要样式:

<style name="SplashTheme" parent="AppTheme">

        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:windowBackground">@drawable/splashscreen</item>

    </style>

<style name="Mainstyle" parent="Theme.AppCompat.Light.NoActionBar">

    <!-- Customize your theme here. -->

            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>

</style>

3)在主要活动中,在 super.onCreate()方法之前添加此行:

setTheme(R.style.Mainstyle);

4)将主题添加到清单文件中,如下所示:

<activity
            android:name=".MainActivity"
            android:theme="@style/SplashTheme">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>

这是在 Android开发者网站中 Google 推荐正确方式。