Splash-screen approach in single Activity app(单一活动应用程序中的闪屏方法)
本文介绍了单一活动应用程序中的闪屏方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力决定创建应用程序闪屏的最佳方法,同时考虑谷歌关于尽可能选择单个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);
}
这是我一直在使用的方法,即使有多个活动,因为它遵循谷歌制定的指导方针:它立即显示飞溅,不会停留超过需要的时间。
这篇关于单一活动应用程序中的闪屏方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:单一活动应用程序中的闪屏方法
基础教程推荐
猜你喜欢
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
