Android avoid APP start flash black (Theme and Style)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

  A few days ago, Boss reaction, the machine every time you start the program will flash a black screen, the customer does not accept the. No way, can only think about how to solve, finally found the following method. Black is the main causes of flash when we start Activity, need to run onCreate and onResume will display interface. That is to say to some data, will be displayed. According to this idea, is it right? I put the work to reduce can avoid screen? The fact is, even if you onCreate what all don't do, will flash a black screen, because of the need for a certain period of time to initialize the analytic interface. The following is the solution:

(PS: The new QQ group, who are interested can join together: Android group: 322599434)  

1,Custom Theme

//Edited by mythou
//1,Sets the background Theme
<style name="Theme.AppStartLoad" parent="android:Theme">  
    <item name="android:windowBackground">@drawable/ipod_bg</item>  
    <item name="android:windowNoTitle">true</item>  

//2,Set up a transparent Theme
<style name="Theme.AppStartLoadTranslucent" parent="android:Theme">  
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowNoTitle">true</item>  

  I define two Theme, the first kind of Theme is setting a background image. When the program starts, the first display a background image, to avoid black. The second Theme is the style is set to transparent, proceedings not black but the entire transparent, wait until after the one-time initialization interface display. Here to talk about the advantages and disadvantages of the two ways:

2,Modify the AndroidManifest.xml

In order to make the entry into force of the Theme above, we need to set some Activity Theme

//Edited by mythou

<!The main interface of iPod>

  <!Style mythou-- - using the above definition> android:theme="@style/Theme.AppStartLoad" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> //...... </application>

  • Can increase the above custom styles in Activity. In addition to increase in Application is also possible, but the overall effect.
  • Custom Theme in /res/values/styles.xml. If no such file, add a can.
  • If there are multiple Activity switching, intermediate may also exist a short black screen problem. When reason is Activity to start the initialization required loading data, if you want to avoid this situation, you can switch Activity increases above the style.
  • The above two kind of styles can be avoid screen. You can test your program to choose an effect.
  • This is to avoid a black screen, but if you initialize boot slowly, still give people the feeling of a slow start procedure. The need to optimize the initialization process.


3,The Theme property.

//Edited by mythou
android:theme="@android:style/Theme.Dialog" //Activity display as a dialog model

android:theme="@android:style/Theme.NoTitleBar" //Don't show the application title bar of the android:theme= "@android:style/Theme.NoTitleBar.Fullscreen" // not to show the application of the title bar, And full screen android:theme="Theme.Light " //The background is white android:theme="Theme.Light.NoTitleBar" //The white background and no title bar android:theme="Theme.Light.NoTitleBar.Fullscreen" //White background, No title bar, Full android:theme= "Theme.Black" / "Theme.Black.NoTitleBar" android:theme= black background / black background and no title bar of the android:theme= "Theme.Black.NoTitleBar.Fullscreen" // black background, No title bar, Full android:theme= "Theme.Wallpaper" // with the desktop for the application background of android:theme= "Theme.Wallpaper.NoTitleBar" // with desktop application background, And no title bar of the android:theme= "Theme.Wallpaper.NoTitleBar.Fullscreen" // with desktop application background, No title bar, Full screen android:theme="Theme.Translucent" //Transparent background android:theme="Theme.Translucent.NoTitleBar" //Transparent background no titles android:theme="Theme.Translucent.NoTitleBar.Fullscreen" //Transparent background no titles, Full android:theme= "Theme.Panel" // android:theme= display panel style "Theme.Light.Panel" // flat panel display style

4,Theme and Style

  Android except Theme and Style, for example, the following is a Style Launcher workspace configuration

//Edited by mythou
  <style name="WorkspaceIcon">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_gravity">center</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:singleLine">true</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:textSize">12sp</item>
        <item name="android:textColor">#FFF</item>
        <item name="android:shadowRadius">2.0</item>
        <item name="android:shadowColor">#B0000000</item>

Style can be understood as a set of attribute set, convenient for different View settings to use, when we use Style in View, using the Theme method is applied to the same. What are the differences between Style and Theme? Below is a list of the differences:

  • The style used in the single View, such as: Button, TextView etc.
  • Theme by AndroidManifest.xml <application> and <activity> used in the entire application or a Activity theme, global impact on the entire application or a Activity.
  • If an application used theme, while application under view also used the style, so when a conflict occurs when the theme and style attributes, style has priority over the subject.

  It is solved by Theme flash black start program, and on the Theme and Style, through the Theme configuration, but can also be a welcome page. But we all want to program the faster the better, it still needs a lot of optimize their programs.


Edited by mythou

The original Bowen, reprint please indicate the source  

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Iris at November 13, 2013 - 2:51 PM