Android启动界面优化技巧-Splash Screens的正确方式

本文探讨了如何在Android应用中优化启动界面,防止白屏问题。通过在styles.xml中创建SplashTheme主题,并在启动活动(SplashActivity)中应用,可以改善启动体验。参考Google的设计指南和外部资源,实现一个有效的Splash Screen解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

备注:这里是开发跨平台App时,适配Android启动屏幕,主要为了防止白屏。玩Android开源App 往往我们在开发Android的时候会出现白屏等等,主要原因就是启动时需要加载的资源过多,从而影响了Android启动,Google建议的启动方式:www.google.com/design/spec…,如果能够翻越围墙的同学可以看一下??? 好了我们下面就直接说明了

1. 在res/drawable下创建一个bg_splash.xml文件,并写下下面的内容
其中@drawable/splas是一张图片,来自drawable文件夹下 其中@color/gray是灰色,来自colors.xml文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/gray" />
    <item>
        <bitmap
            android:src="@drawable/splash" />
    </item>
</layer-list>
  1. 在styles.xml文件下创建SplashTheme的主题,引入bg_splash

     <!-- Base application theme. -->
     <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
         <!-- Customize your theme here. -->
     </style>
    
     <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
         <item name="android:windowBackground">@drawable/bg_splash</item>
     </style>
    

3.在你的启动界面中引入SplashTheme,如下

<activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            android:noHistory="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

最终就完成了 在SplashActivity中,你可以setContentView加载View,也可以不用 参考资源:https://www.bignerdranch.com/blog/splash-screens-the-right-way/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值