我希望我的应用看起来更专业,所以我决定添加一个启动画面。
我应该如何进行实现?
最佳答案
请注意,此解决方案不会让用户等待更多:启动画面的延迟取决于应用程序的启动时间。
当您打开任何 android 应用时,默认情况下您会看到一个黑色的屏幕,上面有应用的标题和图标,您可以通过使用样式/主题来更改它。
首先,在 values 文件夹中创建一个 style.xml 并为其添加样式。
<style name="splashScreenTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
除了使用 @android:style/Theme.DeviceDefault.Light.NoActionBar
您可以使用任何其他主题作为父主题。
其次,在您的应用 Manifest.xml 中将 android:theme="@style/splashScreenTheme"
添加到您的主要 Activity 中。
<activity
android:name="MainActivity"
android:label="@string/app_name"
android:theme="@style/splashScreenTheme" >
第三,在 onCreate() 启动 Activity 中更新您的主题。
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.mainAppTheme);
super.onCreate(savedInstanceState);
}
更新 查看 this post .
感谢@mat1h 和@adelriosantiago
关于android - 如何制作启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5486789/