android App冷启动优化

       android App冷启动优化,实现点击App Logo,立马又相应,而且不会白屏和黑屏;优化用户体验!

 

参考:https://www.cnblogs.com/xunzhi/p/5794793.html
    
    第一步:launcher_background.xml (drawable)
            <?xml version="1.0" encoding="utf-8"?>
            <!-- Modify this file to customize your launch splash screen -->
            <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

                <!-- 启动页面的背景图片   (图片大小需要注意,我这边图片的宽高比例是1:2) -->
                <item android:drawable="@mipmap/beijing_whole" />        

                
                <!-- 整体的背景颜色 -->
                <!--<item android:drawable="@android:color/transparent" />-->
                <!--<item >-->
                    <!--<bitmap android:src="@mipmap/beijing_whole"/>-->
                <!--</item>-->
                
            </layer-list>
            
    第二步:styles.xml
            <!-- Base application theme. -->
            <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
                <!-- Customize your theme here. -->
                <item name="colorPrimary">@color/colorPrimary</item>
                <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
                <item name="colorAccent">@color/colorAccent</item>

                <!--将ActionBar隐藏,这里使用ToolBar-->
                <item name="windowActionBar">false</item>
                <!-- 使用 API Level 22以上编译的话,要拿掉前綴字 -->
                <item name="windowNoTitle">true</item>
                <item name="alertDialogTheme">@style/alert_dialog_theme</item>
            </style>

            <!-- 启动页面设置成全屏展示和windowBackground -->
            <style name="AppTheme.Launcher">
                <item name="android:windowFullscreen">true</item>
                <item name="android:windowBackground">@drawable/launcher_background</item>
            </style>

            
    第三步:manifest.xml
    
            <application
                ……………………
                android:theme="@style/AppTheme"
                ………………>
                
            <activity android:name="………….WelcomeActivity"
                android:theme="@style/AppTheme.Launcher"
                android:screenOrientation="portrait">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            
    第四步:activity_welcome.xml
    
            设置启动页面的背景为透明色:(因为启动页面已经设置了theme背景,所以这里再次设置背景多余,也有可能拉伸图片的效果)
            
            <?xml version="1.0" encoding="utf-8"?>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/transparent">

            </LinearLayout>
    
    第五步:MainActivity.java
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {

                // 冷启动优化后重新设回原来的主题
                setTheme(R.style.AppTheme);

                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_welcome);
            }

 

 

android studio,使用flutter开发,冷启动优化的处理:

    1》、flutter工程,对android studio已经做过处理的;在style.xml里:
    
    
        <?xml version="1.0" encoding="utf-8"?>
        <resources>
            <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
                <!-- Show a splash screen on the activity. Automatically removed when
                     Flutter draws its first frame -->
                <item name="android:windowBackground">@drawable/launch_background</item>
            </style>

        </resources>
        
    2》、在对应的 launch_background.xml里:
    
        <?xml version="1.0" encoding="utf-8"?>
        <!-- Modify this file to customize your launch splash screen -->
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
            <!--<item android:drawable="@android:color/holo_red_dark" />-->
            <item android:drawable="@mipmap/beijing_whole"/>
        </layer-list>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

漠天515

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值