Android冷启动LaunchActivity部分

创建一个LaunchActivity不要用setContentView()方法进行渲染(耗时),通过Theme添加背景样式即可

public class LaunchActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Intent intent = new Intent(LaunchActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

创建drawable文件作为LaunchActivity的Theme的背景

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 底层白色 -->
    <item android:drawable="@color/white" />

    <!-- 顶层Logo居中 -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/start_page_welcome" />
    </item>
</layer-list>

在styles中为LaunchActivity创建样式

<style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/bg_launch</item>
</style>

在AndroidManifest.xml文件中LaunchActivity注册部分如下配置

<activity android:name=".activity.LaunchActivity"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

注意:如果AppTheme中写了<item name="android:windowIsTranslucent">true</item>属性,可能会导致点击图标后有延迟依然停留在桌面,参考下面AppTheme写法

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:listDivider">@drawable/default_recycler_line</item>
        <!--<item name="android:windowIsTranslucent">true</item>-->
        <item name="android:windowNoTitle">true</item>
    </style>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容