问题
I want to know how to achieve this effect.
My app (default everything), when launcher icon is clicked, right away display some kind of a empty dummy window, where nothing is happening and then loads layout into it.
"Heavier" apps like YouTube, Drive, Dropbox etc. when started, seem to wait after launch, without showing that dummy window and load right into ready layout.
Any idea how to do this or where should I look into?
Thanks
//EDIT: this has nothing to do with something like loading database, where I should display progressBar, imho this has to do with stuff before activity exists.
回答1:
I suggest you don't disable the dummy loading window using:
<style name="Theme.MyTheme" parent="android:style/Theme" >
....
<item name="android:windowDisablePreview">true</item>
....
</style>
because you could run into several problems. For example, if you try to animate an AlertDialog, enter animation will not work (personal experience).
The right solution is to set the theme of your application like to your main activity screen (same ActionBar style, same background color). In my application after severals experiments i found the right solution for my needs. (I have a main activity with blank background, no ActionBar, just full screen personal layout)
1 - styles.xml: add new style like this (remove ActionBar and set the same background color of my main activity)
<style name="LoadingTheme" parent="@android:style/Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@color/white_smoke</item>
</style>
2 - AndroidManifest.xml: set my theme for main activity to "LoadingTheme"
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.company.appname.MainActivity"
android:label="@string/app_name"
android:theme="@style/LoadingTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
....
</application>
And finally i have full blank dummy loading window without ActionBar with soft MainActivity load and working animations.
Hope to be helpful.
回答2:
<style name="Theme.MyTheme" parent="android:style/Theme" >
....
<item name="android:windowDisablePreview">true</item>
....
</style>
but use with caution
回答3:
You can call the setContentView
method anywhere you'd like in your activity. Before calling this method it will display a blank screen. If you wanted a splash screen, you can call the setContentView
method within the onCreate
method to display the splash screen view. Then when you're ready to display the "main" view you can use a LayoutInflater
to display it. I also suggest using a ProgressDialog
to show the user that information is loading.
回答4:
Load your resources before setting the contentview. There will be a dummy window until you would not set view using setContentView.
EDIT To avoid this screen. Make there changes to your code.
1) Do not do any heavy work in activity onCreate method. Run a separate thread for it.
2) Set content view right after the super.onCreate() line
super.onCreate(savedInstanceState);
setContentView (R.layout.splash_screen);
3) Apply following theme to your application.
Define theme in style
<resources>
<style name="Theme.MyTheme" parent="android:style/Theme" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/any_default_background</item>
</style>
</resources>
In your Manifest
<application
....
android:theme="@style/Theme.MyTheme"
....
>
Thats It.
回答5:
This will create a custom preview window for your activity.
Create a style in styles.xml like
<style name="MyTheme" parent="@android:style/Theme.Holo.NoActionBar">
<item name="android:windowBackground">@color/myBackgroundColor</item>
</style>
In your Manifest file use the theme created above. For eg:
<activity android:name=".MyActivity"
android:label="@string/app_name"
android:theme="@style/MyTheme"
/>
In your activity change the background of the window back to null in onCreate()
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(null);
setContentView(R.layout.main);
}
来源:https://stackoverflow.com/questions/16922915/android-disable-dummy-starting-window-of-application