【发布时间】:2017-01-14 13:32:41
【问题描述】:
我正在尝试在 MainActivity 之前实现启动画面,但无法使其正常工作。我按照此处的说明进行操作:https://www.bignerdranch.com/blog/splash-screens-the-right-way/。目前除了黑色延迟屏幕什么都没有出现。请告诉我哪里出错了。谢谢。
Splash.java
public class Splash extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
finish();
}
}
background_splash.xml
<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>
styles.xml
<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>
【问题讨论】:
-
在调用 Intent 意图之前 .. 给它一些时间来显示像 2/3 秒这样的飞溅
-
是的,我会试试的。
-
new Handler().postDelayed(new Runnable() { @Override public void run() { // Your Intent } }, 2000); -
谢谢。我发现了问题。
background_splash.xml根本没有显示。你知道为什么它可能没有显示吗? -
还要确保其他活动 WelcomeActivity 具有正确的主题,否则它将继承自您的主应用主题
android:theme="@style/SplashTheme"
标签: java android android-xml android-styles