每次用户打开应用时,我们都会使用初始屏幕显示公司徽标。目前,我们正在显示3秒的启动画面。
以下是代码:
private static int SPLASH_TIME_OUT = 3000; // Delay of 3 Seconds
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
Intent i = new Intent(SplashScreenActivity.this, AnotheActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
但是这个启动画面持续时间只是在团队中随机选择的。 我们知道Splash屏幕在Android应用程序生态系统中并不是那么令人鼓舞,但由于这是我们应用程序的需要,因此它已经实现。
我的问题:是否有任何标准的Android指南/最佳做法来选择正确的启动画面持续时间?
答案 0 :(得分:3)
更好的选择是使用具有自定义主题的启动画面活动,以启动主要内容活动。有了这个,就不需要使用计时器了,因为它在应用程序准备就绪时切换到主要内容,同时显示主题内的图片。
以下是教程如何操作 - https://www.bignerdranch.com/blog/splash-screens-the-right-way/
教程的主要部分:
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"> THEME HERE!!!
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</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();
}
}
<style name="SplashTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/black"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo_image"/>
</item>
</layer-list>
甚至可以将样式添加到应用程序中,而无需使用单独的活动。
答案 1 :(得分:1)
启动屏幕它是不好的做法,当它可能不使用它时请避免使用闪屏。您可以阅读有关此link1,link2的一些文章。
但是,如果需要通过创建覆盖android:windowBackground
的自定义主题来显示启动而不是使用,则在调用super.onCreate()
之前用标准主题替换该自定义主题。以下是tutorial的实施和详细说明。
假设您有一个名为AppTheme的主题,您的启动器主题将是:
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
然后使用android:theme="@style/AppTheme.Launcher".
转换回普通主题的最简单方法是在super.onCreate()和setContentView()之前调用setTheme(R.style.AppTheme):
public class MyMainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.Theme_MyApp);
super.onCreate(savedInstanceState);
// ...
}
}
答案 2 :(得分:0)
Google指南非常明确。 仅在必要时使用闪屏。 (如果您没有向用户显示任何内容)它应该只有在您显示一些数据之后才可见。 如果您使用谷歌应用程序,您将会看到一个闪屏。 有更聪明的方法来为您的应用程序打造品牌。 您可以找到更多数据here。
答案 3 :(得分:0)
社区认可的标准解决方案正在使用启动主题。