单一活动应用程序中的闪屏方法 [英] Splash-screen approach in single Activity app

查看:25
本文介绍了单一活动应用程序中的闪屏方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力决定创建应用程序闪屏的最佳方法,同时考虑谷歌关于尽可能选择单个Activity应用程序的最新建议。

查看此处:

"The new approach is to use one-activity structure whenever possible."

和这里:

"Today we are introducing the Navigation component as a framework for structuring your in-app UI, with a focus on making a single-Activity app the preferred architecture."

我发现的任何好的闪屏方法都有专门的闪屏活动:

See here

and here

其他人有在单个活动应用程序中创建闪屏的经验吗?单项活动建议是包括闪屏还是特例?有没有人在这方面有什么好的例子或建议?

干杯, 保罗。

推荐答案

我使用的方法如下:

首先为背景定义一个可抽屉:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/green"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

2.定义要在初始屏幕中使用的新样式:

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

3.使用Splash主题实现您的活动:

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

4.在创建时、超级调用之前和设置内容视图之前设置默认应用程序主题:

override fun onCreate(savedInstanceState: Bundle) {
    setTheme(android.R.style.AppTheme)
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main);
}

这是我一直在使用的方法,即使有多个活动,因为它遵循谷歌制定的指导方针:它立即显示飞溅,不会停留超过需要的时间。

这篇关于单一活动应用程序中的闪屏方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆