Android 如何使用合适的方法添加闪屏
我需要一个合适的方式来实现android中的启动屏幕。正如我提到的一些例子,但它们不推荐使用Android 如何使用合适的方法添加闪屏,android,Android,我需要一个合适的方式来实现android中的启动屏幕。正如我提到的一些例子,但它们不推荐使用 new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(MainSplashScreen.this, FirstScreen.class); startActivity(i); finish(); } }
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(MainSplashScreen.this, FirstScreen.class);
startActivity(i);
finish();
}
}, 5*1000);
这是一个坏习惯。你应该尽可能快地运行你的应用程序。用户不想等待 不必等待,只需创建一个活动并通过样式文件为其分配windowBackground
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
@可绘制/飞溅背景
splash_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/green" />
<item android:gravity="center">
<bitmap android:src="@drawable/brand" android:gravity="center" />
</item>
</layer-list>
可能重复的您能否显示Splash类的导入部分?如果您要转到,请进一步说明。如何以正确的方式执行此操作查看示例创建一个空活动并在清单中分配AppTheme.Launcher,下一步编辑您的Splash\u background drawable