Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
124 views
in Technique[技术] by (71.8m points)

android - How do I make a splash screen?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Note this solution will not let the user wait more: the delay of the splash screen depends on the start up time of the application.

When you open any android app you will get by default a some what black screen with the title and icon of the app on top, you can change that by using a style/theme.

First, create a style.xml in values folder and add a style to it.

<style name="splashScreenTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

Instead of using @android:style/Theme.DeviceDefault.Light.NoActionBar you can use any other theme as a parent.

Second, in your app Manifest.xml add android:theme="@style/splashScreenTheme" to your main activity.

<activity
        android:name="MainActivity"
        android:label="@string/app_name"
        android:theme="@style/splashScreenTheme" >

Third, Update your theme in your onCreate() launch activity.

protected void onCreate(Bundle savedInstanceState) {
    // Make sure this is before calling super.onCreate
    setTheme(R.style.mainAppTheme);
    super.onCreate(savedInstanceState);
}

UPDATE Check out this post.

Thanks to @mat1h and @adelriosantiago


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...