Android avoids app splash screen resolution (theme and style)

Source: Internet
Author: User

The main reason for the flashing black screen is that when we start the activity, we need to run the OnCreate and Onresume to show the screen flash screen because the main reason is that when we start the activity, we need to run through OnCreate and Onresume to display the interface. This means that some data needs to be processed before it is displayed. According to this idea, is it possible to avoid a black screen if I minimize the initialization work? The fact is, even if you do not do anything oncreate, still will flash a black screen, because it takes a certain time to initialize the parsing interface. Here is the workaround:

1. Custom Theme

Copy CodeThe code is as follows:
Setting the background map theme
<style name= "Theme.appstartload" parent= "Android:theme" >
<item name= "Android:windowbackground" > @drawable/ipod_bg</item>
<item name= "Android:windownotitle" >true</item>
</style>
2. Set Transparent theme
<style name= "theme.appstartloadtranslucent" parent= "Android:theme" >
<item name= "Android:windowistranslucent" >true</item>
<item name= "Android:windownotitle" >true</item>
</style>
I've defined two types of theme, the first of which is to set a background map. When the program starts, this background image is displayed first to prevent a black screen from appearing. The second kind of theme is to set the style to transparent, the program will not be black screen after startup, but the whole transparent, wait until the interface is initialized to show it once. Here are the pros and cons of two ways:
the theme1 program starts quickly, the interface displays the background map first, and then refreshes the other interface controls. Give people a refreshing feeling of being out of sync.
theme2 give the program start slow feeling, the interface once brush out, refresh synchronization.

2, modify the Androidmanifest.xml
To make the above theme effective, we need to set up some activity theme
Copy CodeThe code is as follows:
<application
Android:allowbackup= "true"
android:icon= "@drawable/ipod_icon"
Android:label= "@string/app_name"
Android:launchmode= "Singletask" >
<!--ipod main screen--
<activity
Android:name= "Com.apical.apicalipod.IPodMainActivity"
<!--use the styles defined above mythou-->
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>
• You can add the above custom style to the activity. It is also possible to increase the application inside, and it is a global effect.
• Custom theme placed inside the/res/values/styles.xml. If you do not have this file, you can add one yourself.
• If there are multiple activity transitions, there may be a transient black screen problem in the middle. The reason is that when the activity starts, it needs to initialize the loading data, and if you want to avoid this, you can add the above style to the activity you switched.
• Both of the above styles can avoid a black screen. You can actually test your program to choose an effect.
• This is just a black screen to avoid, but if you start the program initialization slow, still will give the program to start a slow feeling. You need to optimize your program initialization process yourself.
 
3, Theme attribute detailed
Copy CodeThe code is as follows:
Android:theme= "@android: Style/theme.dialog"//activity displayed as dialog box mode
Android:theme= "@android: Style/theme.notitlebar"//Do not display the application title bar
Android:theme= "@android: Style/theme.notitlebar.fullscreen"//Do not display the application title bar and full screen
Android:theme= "Theme.light"//Background is white
Android:theme= "Theme.Light.NoTitleBar"//white background with no title bar
Android:theme= "Theme.Light.NoTitleBar.Fullscreen"//white background, no title bar, fullscreen
Android:theme= "Theme.black"//Background Black
Android:theme= "Theme.Black.NoTitleBar"//black background with no title bar
Android:theme= "Theme.Black.NoTitleBar.Fullscreen"//black background, no title bar, fullscreen
Android:theme= "Theme.wallpaper"//using the system desktop as the application background
Android:theme= "Theme.Wallpaper.NoTitleBar"//using the system desktop as the application background with no title bar
Android:theme= "Theme.Wallpaper.NoTitleBar.Fullscreen"//Use System desktop for application background, no title bar, fullscreen
Android:theme= "theme.translucent"//Transparent Background
Android:theme= "Theme.Translucent.NoTitleBar"//Transparent background with no caption
Android:theme= "Theme.Translucent.NoTitleBar.Fullscreen"//Transparent background with no caption, fullscreen
Android:theme= "Theme.panel"//panel style display
Android:theme= "Theme.Light.Panel"//Tablet style display
4, Theme and style
Android has a style in addition to theme, such as the following is a style launcher inside the configuration workspace
Copy CodeThe code is as follows:
<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>
Style can be understood as a set of attributes, which is convenient for different view settings, and is the same as using theme when we use style in view. So what's the difference between style and theme?

The differences are listed below:
• Styles are used in separate view, such as Button, TextView, etc.

• Themes use <application> and <activity> in Androidmanifest.xml for the entire application or for an activity that has a global impact on the entire app or on an activity.

• If a theme is used by an app and the view in the app is also styled, the style takes precedence over the theme when the theme conflicts with the style attribute.

Above is through the theme solution to start the flash black screen problem, and explained the theme and style, through the theme configuration, in fact, can also be a welcome page. But we all want the program to start faster and better, so we still need to optimize our programs.

Android to avoid app splash screen resolution (theme and style)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.