-1
我爲我的學校項目製作了一個應用程序,我想知道如何將兩件事整合在一起?啓動畫面和應用程序。如何集成啓動畫面活動和應用程序
我爲我的學校項目製作了一個應用程序,我想知道如何將兩件事整合在一起?啓動畫面和應用程序。如何集成啓動畫面活動和應用程序
創建閃屏的活動像這樣去實現它
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)創建繪製文件中像名爲splashscreen:
<?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)在你主要活動前超加入這一行。的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開發者網站 recomended。