Solve the Problem of starting a black screen of the Activity and setting the android: javaswistranslucent incompatible activity to switch the animation.

Source: Internet
Author: User

Solve the Problem of starting a black screen of the Activity and setting the android: javaswistranslucent incompatible activity to switch the animation.

 

I didn't pay much attention to this issue when I was doing the APP, because when I was using other apps, I would also have a black screen flashing at the beginning of the application startup before the application's welcome page would appear. Until the recent development process, I found that the thread I started on the welcome page was too large due to the amount of data requested and processed, leading to a brief white pop-up screen on the welcome page before it appeared, of course, the white pop-up screen is stuck because the theme style android: Theme = @ style/AppTheme uses theme. in Light mode, the values of windowBackground, colorBackground, colorForeground, and other properties of the Light style are light, that is, Light is highlighted in white. The following code is used to reference the style when my APP displays a white pop-up screen:

  

After a simple modification, the screen color is black. The Code is as follows:

  

After the code is modified, the referenced style is black, but the welcome page still has a black pop-up screen. Continue to modify and set the transparent property to true. The Code is as follows:

 

After this modification, the black pop-up screen disappears and eventually achieves its desired effect. Finally, I found that someone has summarized and handled this type of problem after reading the data, and analyzed the advantages and disadvantages. Here I will reference it with my understanding.

There are two ways to avoid black flashing: 1. Set the background image for Theme; 2. Set the transparent attribute for Theme. Obviously, I am using the second method. First, let's look at the code referenced in the two methods:

    
 
    
 

In the above two Theme types, after setting the background image for Theme, the program will first display this image when it is started to avoid black screen; set transparent properties for Theme, after the program is started, it is transparent instead of a black screen. It is displayed only once after the interface Initialization is complete. The following are the advantages and disadvantages of the two methods:

  • Set the background image for Theme to give people a quick start feeling. The background image is displayed on the Interface first, and other interface controls are refreshed before refreshing and not synchronizing.
  • Set transparent properties for Theme to give people the feeling that the program is slow to start. The interface will be refreshed at one time to refresh the synchronization.

    However, the problem arises. After the activity switching animation effect is configured, the animation fails to be switched after the android: javaswistranslucent = true setting is completed. At the moment, I do not know the complexity of the relationships between theme attributes of the android system, and inherit from them... Why is there such a problem? But I found a solution accidentally.

     


    Configure the parent inherited by style

     

     


    Then let the apptheme
    Android: windowAnimationStyle is the style above

     

     


    If you want to use this theme when switching all the activities, you can configure the application or a single configuration in the activity.

     

    Of course, when the homepage exits, You can separately configure the MainActivity exit animation and enter the animation.

     

     

    The exit and entry animation of MainActivity can be referenced by the system, but it seems that the anim of some systems cannot be referenced in the style configuration,

    Under the folder sdkplatformsandroid-20data es, activity_open_enter.xml, activity_close_exit.xml can be directly copied to the project, modify

    Write one entry or exit separately, and then use other default values .......

     

    More hands-on and test. If there is any error, please leave a message for discussion. Thank you.

    Copy to Google Translate translation result ROBOT: windowAnimationStyle

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.