Mtk-android app starts flashing black screen (Theme & Style)

Source: Internet
Author: User

splash screen Reason: mainly when we start the activity, we need to run out of OnCreate and Onresume;
The Android system needs to process some data 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, will still flash a black screen, because the initialization of the parsing interface takes a certain amount of time, the following is the workaround:

1. Custom Theme
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 have two themes defined above:
The first kind of theme is to set up 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 black screen after startup, but the whole transparent, wait until the interface initial
After the completion of the display only once. Here are the pros and cons of two ways:

Topic 1: The 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.
Theme 2: The program starts slowly feeling, the interface brushes out once, refreshes the synchronization.

2, modify the Androidmanifest.xml
In order for the above theme to take effect, we need to set up some activity theme
<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.
The custom theme is 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
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
<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.

Topics are used throughout the app or an activity through <application> and <activity> in Androidmanifest.xml, and the theme has a global impact on the entire app or on an activity.

If a theme is used by an app and the view under the app also uses styles, 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.

Mtk-android app starts flashing black screen (Theme & Style)

Related Article

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.