Android冷启动黑白屏

2019-05-05  本文已影响0人  君莫看

一、制作一个启动屏的.9图片

layer-list 也可以

根据需求做拉伸效果(上左拉伸背景,右下拉伸内容),保存到drawable目录

创建9图.png

二、创建新主题

res => values => styles.xml下创建如下主题(如:AppTheme.StartingWindowTheme

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@android:color/transparent</item>
        <item name="android:itemBackground">@color/backgroundColor</item>
    </style>

    <!-- 应用启动页(StartingWindow)的theme -->
    <style name="AppTheme.StartingWindowTheme" parent="AppTheme">
        <!-- 可以设置成纯颜色(设置一个和Activity UI相似的背景) -->
        <!--<item name="android:windowBackground">@color/startingwindow_bgcolor</item>-->
        <!--也可以设置成一张图片 -->
        <item name="android:windowBackground">@drawable/ic_launcher_screen</item>
        <item name="android:windowFullscreen">true</item>
    </style>

三、在AndroidManifest.xml使用该主题

在系统启动的第一个activity中使用该主题

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ak.aigo">

    <application
        android:name=".app.AiGoApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launchera"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".ui.splash.SplashActivity"
            android:theme="@style/AppTheme.StartingWindowTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
上一篇 下一篇

猜你喜欢

热点阅读