1.给Activity设置独立的样式(theme)
<activity android:name="com.example.myapplication.SplashActivity"
android:theme="@style/AppTheme.LauncherTheme2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
具体的样式如下:
<style name="AppTheme.LauncherTheme2">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/splash_preview</item>
</style>
splash_preview.xml内容如下,可以根据实际需求进行自定义
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/holo_red_light"></item>
<item android:top="30dp">
<bitmap
android:gravity="top"
android:src="@drawable/ic_launcher_round"></bitmap>
</item>
</layer-list>
2.给Activity设置布局样式
public class SplashActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);//非必须
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
try {
Thread.sleep(600);//可以实现伪动画的渐变效果,实际开发中可以用具体业务来替代(做代码初始化等)
// 提前初始化 某些代码?
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}