Google 的Android Splash

简介: first create an XML drawable in res/drawable. Here, I’ve set up a background color and an image.

first create an XML drawable in res/drawable.

    <?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:gravity="center"
        android:src="@mipmap/ic_launcher"/>
    </item>
  </layer-list>

Here, I’ve set up a background color and an image.
Next, you will set this as your splash activity’s background in the theme. Navigate to your styles.xml file and add a new theme for your splash activity::

    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
         <!-- Customize your theme here. -->
        </style>

        <style name="SplashTheme"         parent="Theme.AppCompat.NoActionBar">
        <item   name="android:windowBackground">@drawable/background_splash</item>
        </style>

  </resources>

In your new SplashTheme, set the window background attribute to your XML drawable. Configure this as your splash activity’s theme in your AndroidManifest.xml:

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

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

Finally, your SplashActivity class should just forward you along to your main activity:

public class SplashActivity extends AppCompatActivity {

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

    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
}
}

Notice that you don’t even set up a view for this SplashActivity. The view comes from the theme. When you set up the UI for your splash activity in the theme, it is available immediately.
If you did have a layout file for your splash activity, that layout file would be visible to the user only after your app has been fully initialized, which is too late. You want the splash to be displayed only in that small amount of time before the app is initialized.

form:https://www.bignerdranch.com/blog/splash-screens-the-right-way/

look:https://www.bignerdranch.com/blog/

目录
相关文章
|
3月前
|
IDE API 开发工具
Google I/O :Android Jetpack 最新变化(四)Compose
Google I/O :Android Jetpack 最新变化(四)Compose
102 0
|
3月前
|
JSON IDE 测试技术
Google I/O :Android Jetpack 最新变化(二) Performance
Google I/O :Android Jetpack 最新变化(二) Performance
112 0
|
3月前
|
SQL API Android开发
Google I/O :Android Jetpack 最新变化(一) Architecture
Google I/O :Android Jetpack 最新变化(一) Architecture
68 0
|
6月前
|
API 开发工具 Android开发
解决 Android App 上架 Google play后 ,签名变更,第三方sdk无法登录
解决 Android App 上架 Google play后 ,签名变更,第三方sdk无法登录
147 0
|
7月前
|
传感器 安全 Android开发
Google发布 Android 12 开发预览版
Google发布 Android 12 开发预览版
85 1
|
API Android开发 图形学
【Unity3D】Android App Bundle(aab)打包上架Google Play介绍
总体说来,Android App Bundle打包有3种方式,每种方式都有成功上架Google Play进行测试通过,因此实用程度还是挺高的。能够理解以下内容的前提是会打apk包,知道如何生成Asset Bundle文件,这块内容可以参考我的上一篇文章。
1074 0
【Unity3D】Android App Bundle(aab)打包上架Google Play介绍
|
3月前
|
API Android开发
Google I/O :Android Jetpack 最新变化(三)UI
Google I/O :Android Jetpack 最新变化(三)UI
49 0
|
6月前
|
JavaScript Java 开发工具
Cocos Creator Android 平台接入 Google Firebase (Analytics功能)(二)
Cocos Creator Android 平台接入 Google Firebase (Analytics功能)
155 0
|
6月前
|
存储 JavaScript Java
Cocos Creator Android 平台 Google 原生登录(二)
Cocos Creator Android 平台 Google 原生登录
124 0
|
6月前
|
API 开发工具 Android开发
Cocos Creator Android 平台 Google 原生登录(一)
Cocos Creator Android 平台 Google 原生登录
185 0