Android Add full Screen splash screen

Source: Internet
Author: User

some Android software needs to display a splash screen at startup, can be a picture or some set what, there is also a good thing is that the opportunity to load data in the background.

There are generally two ways to create a splash screen:
1, create an activity, display the splash screen, and then start the main activity
2, the main activity to create a display area, and then hidden away.

The second one is actually simpler, but this one shows up in the code, how uncomfortable it is, and it's possible to design efficiency issues. So in the project still choose the first kind.


First set up an activity, here is clearly helloactivity, interface is activity_hello.xml.

Next, modify the Androidmanifest.xml file to change the main activity to helloactivity. Put the previous main activity below.

<ActivityAndroid:name= "Com.phone.config.SetActivity"Android:icon= "@drawable/set"Android:label= "@string/app_name"android:screenorientation= "Landscape"Android:theme= "@android: Style/theme.notitlebar.fullscreen"Android:windowsoftinputmode= "Adjustunspecified|statehidden" ><Intent-filter><ActionAndroid:name= "Android.intent.action.MAIN" /><categoryAndroid:name= "Android.intent.category.LAUNCHER" /></Intent-filter></Activity>

In this way, the helloactivity starts up, writes the code in the Java file, and starts the main screen when the screen is finished.

In Activity_hello.xml in a linearlayout and a imageview, the interface is very simple, but to ensure that he full screen, in fact, we have set the file inside the full screen, in the Java file OnCreate method can also be set:

@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Set Untitledrequestwindowfeature (Window.feature_no_title); //Set Full ScreenGetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN    );    Setcontentview (R.layout.activity_hello); IV= (ImageView) This. Findviewbyid (R.ID.IV); Timer=NewTimer (true); Timer.schedule (Hello,200, 150);//latency 200 milliseconds execution, once every 150 milliseconds}

Here is a timer, with a timer because, my project start screen is a dynamic, but Android does not support GIF play, but the project in this place to use GIF, so the GIF is divided into JPG files, and then played with a timer, When playback is complete, the new activity is loaded.

Write the TimerTask class of the timer and rewrite the run () method.

TimerTask Hello =NewTimerTask () {@Override Public voidrun () {if(Index &lt; 5) {Index++; Message msg=NewMessage (); Msg.what=index;        Handler.sendmessage (msg); }Else if(Index &lt; 8) {Index++;//still a moment}Else{            //stop playback, start main activityTimer.cancel (); Intent Intent=NewIntent (helloactivity. This, Mainactivity.class);            StartActivity (Intent);  Finish (); //do not add this sentence, press the Back button will return to the welcome interface is unreasonable.         }    } };

This also involves a message processing, because Android does not allow other threads to manipulate the UI, but the handle of processing system messages is available, so the timer periodically sends a message to handle to change the interface.

FinalHandler Handler =NewHandler () {@Override Public voidhandlemessage (Message msg) {//Looping PicturesIv.setbackgroundresource (Hellores[msg.what]); }};

In this way, a simple splash screen is ready.

Tip: In the Android4.0 version, this method cannot hide the system's status bar and needs to modify the underlying code.


Source: http://www.cnblogs.com/mnight/p/3677662.html

From for notes (Wiz)

Android Add full Screen splash screen

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.