博客地址:zeyang’s blog
应用有了启动画面后发现,在点击应用后还是会先黑屏一下,所以查了一下怎么解决。
刚开始,以为那个黑色是application加载所用的时间太长,就把application的onCreat()
里初始化的东西都注释掉,发现还是有黑屏,而且时间没有缩短的样子。
后来发现了解决方法:
改变启动页面那个activity的theme。
在styles.xml里添加一个theme:
<style name="SplashTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@drawable/splash</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
主要是<item name="android:windowBackground">@drawable/splash</item>
这句,把启动界面的图片放在这里当做背景图片。
然后再manifest.xml文件里使用这个theme
比如我的启动页面是SplashActivity.class:
<activity
android:name=".ui.activities.SplashActivity"
android:theme="@style/<span style="font-family: Arial, Helvetica, sans-serif;">SplashTheme</span><span style="font-family: Arial, Helvetica, sans-serif;">"></span>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这样再打开应用就发现没有之前的黑色了。。。