[英]Android: Splash Screen Implementation Not Working
I am trying to implement a splash screen before the MainActivity but cannot get it working. 我试图在MainActivity之前实现启动屏幕,但无法使其正常运行。 I followed the instructions found here: https://www.bignerdranch.com/blog/splash-screens-the-right-way/ . 我按照此处的说明进行操作: https : //www.bignerdranch.com/blog/splash-screens-the-right-way/ 。 Currently nothing appears but a black delayed screen. 目前,只有黑色的延迟屏幕显示。 Please tell me where I went wrong. 请告诉我我哪里出问题了。 Thanks. 谢谢。
public class Splash extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
finish();
}
}
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/colorAccent"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash"/>
</item>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
<activity android:name=".Splash"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Simple, Uninstall & install the app again, you will get the splash screen. 简单,再次卸载并安装该应用程序,您将看到启动屏幕。 The problem is due to the instant run in Android Studio 问题是由于在Android Studio中即时运行
To test, give a delay before starting the new activity: 要进行测试,请在开始新活动之前延迟一下:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity();
}
}, 100);
Below super.onCreate(savedInstanceState);
在super.onCreate(savedInstanceState);
add setContentView(R.layout.layout_name.xml);
添加setContentView(R.layout.layout_name.xml);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.