Android冷启动LaunchActivity部分

来源:互联网 发布:喀秋莎录屏软件范例 编辑:程序博客网 时间:2024/05/16 19:47
创建一个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>


原创粉丝点击