Three solutions for black and white screen when Android starts app

You will wonder why some apps will appear black or white for a while before entering the activity interface when they are started, but some apps will not be like QQ mobile terminal. It really needs to be handled here. Let's first understand why this phenomenon occurs. In fact, it is very simple. A simple example of resume can be understood.

In fact, the black or white screen is not abnormal here, but the window background has been displayed before loading into the layout file. The black or white screen is the window background. The code is as follows. You can write a small demo to understand it.

Where is the window background provided? In the provided theme, the white background is provided as follows, that is, the color setting of the white screen for a while at startup.

Therefore, setting windowbackground in theme can solve the problem of blank screen and black screen for a while at startup. The following three solutions are provided:

1、 Provide. PNG background

Providing background image is a solution, but it is necessary to adapt to various screens and provide many pictures. Unless the picture is very complex, you can only use the background picture. Use this method, otherwise I don't recommend it.

2、 Provide. 9.png (ninepatch) background picture

If the picture is not very complex and can be made into a ninepatch picture, then directly make a ninepatch picture and provide one that can be adapted to any mobile phone. Why not.

3、 Use layout list to make background pictures

If you can use this method, it is recommended to use this layout list to make background pictures. The first two use pictures to occupy memory. Using layout list saves memory. Making apps won't say that because there are many pictures, the volume becomes larger.

The code is given below.

Launchactivity is to start the interface for 3 seconds and then jump to the main page mainactivity. In order to display black and white screen more obviously, the thread sleeps for 3 seconds before setcontentview.

activity_ The launcher.xml layout file is very simple. Remember that the background of LinearLayout here is layout_ list_ start_ Pic uses the same background as the theme theme, which eliminates the effect of different background. Here you have to try it yourself to know the benefits and effects of doing so.

Androidmanifest.xml. Note that the theme used by the application is apptheme, and the theme used by the launcheractivity is startapptheme. The effect of this is that as long as the launcheractivity uses the startapptheme theme, other activities use the apptheme theme.

Styles.xml, 2 theme settings

layout_ list_ start_ The pic. XML startup page uses this as the background image

There is also a picture, copyright.png

OK, now provide the effect picture

When starting, the black screen and white screen are transformed into this picture, ha ha~

@H_ 404_ 78@

Launcheractivity interface installed after startup

Adjust to mainactivity interface

That's it. I originally wanted to give GIF animation and took it on wechat. Aoao didn't know how to send it to the computer. Wuwu ~ ~ ~ later I knew that it could be sent to the web wechat...

The download link will be sent later. Oh, shit, I'm going to bed ~ ~~~

If this article is helpful to you, please like it and support it. If you have any questions, please leave a message to discuss it together~

Link to this article: http://www.cnblogs.com/liqw/p/4263418.html

Download address: http://download.csdn.net/detail/lqw770737185/8411705

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>