Just moved from CSDN 51, which was written in 51 in the first blog
So let's talk about such a problem. When your project needs to use the Welcome screen sometimes there will be a short black screen or white screen, so that the user experience is not good, so today teach you how to deal with this problem.
In fact, the black screen or white screen is because the program has not loaded the layout has already shown window Windows background, and the black screen or white screen is the window background. So how to deal with it? Look below ...
public class loadingactivity extends appcompatactivity { @Override protected void oncreate (Bundle savedinstancestate) { super.oncreate ( Savedinstancestate); /* has not yet loaded the layout is sleep 1 seconds, Make sure the black screen or white screen effect is obviously */ try { thread.sleep (; ) } catch (interruptedexception e) { e.printstacktrace (); } Setcontentview (R.layout.activity_loading) /* Welcome page for 2 seconds and jump to mainactivity*/ new thread () { @Override public void run () { try { Thread.Sleep (; ) } catch (interruptedexception e) { E.printstacktrace (); } startactivity (new Intent (Loadingactivity.this,mainactivity.class)); finish (); } }.start (); } }
<?xml version= "1.0" encoding= "Utf-8"? > <manifest xmlns:android= "http// Schemas.android.com/apk/res/android " package=" Com.lg.emptydemo "> <application android:allowbackup= "true" android:icon = "@mipmap/ic_launcher" android:label= "@string/app_ Name " android:supportsrtl=" true " android:theme= "@style/apptheme" > <activity android:name= ". Loadingactivity " android: Theme= "@style/fulltheme" > <intent-filter> <action android:name= " Android.intent.action.MAIN " /> <category android:name= "Android.intent.category.LAUNCHER" / > </intent-filter> </activity> <activity android:name= ". Mainactivity " android:theme = "@style/apptheme" > </activity> </application> </manifest>
Set the style of loadingactivity in Androidmanifest.xml
<style name= "Fulltheme" parent= "AppTheme" > <item name= "Windowactionbar" >false</item> <item name= "Android:windowBackground" >@ Drawable/img_frame_background</item> <item name= "Windownotitle" >true</item> <item name= "Android:windowfullscreen" >true</item> <item name= "Android:windowcontentoverlay" > @null </item> </ Style>
Android:windowbackground Property Set the window background and set it to the Welcome screen.
Source Address: http://down.51cto.com/data/2221953
This article is from the "Liuyvhao" blog, make sure to keep this source http://liuyvhao.blog.51cto.com/11690759/1786830
Short black screen white screen processing when Android project starts