How to create the android welcome Interface

Source: Internet
Author: User

1、create a startup image splash.png and place it in the res-> drawable-hdpi folder.
2. Create a layout file splash. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Background = "@ drawable/Splash">

<Textview
Android: Id = "@ + ID/versionnumber"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignparentbottom = "true"
Android: layout_alignparentright = "true"
Android: layout_marginbottom = "26dp"
Android: layout_marginright = "52dp"
Android: text = "version 1.0"
Android: textcolor = ""/>
</Relativelayout>

Here we use the image created in the previous step as the background image of the startup interface, and then the current program version number is displayed at the bottom of the interface.

3. Create a splashactivity and add the following code to oncreate:

PackageManager pm = getPackageManager();try {    PackageInfo pi = pm.getPackageInfo("com.lyt.android", 0);    TextView versionNumber = (TextView) findViewById(R.id.versionNumber);    versionNumber.setText("Version " + pi.versionName);} catch (NameNotFoundException e) {    e.printStackTrace();}new Handler().postDelayed(new Runnable(){@Overridepublic void run() {    Intent intent = new Intent(SplashActivity.this,SplashScreenActivity.class);    startActivity(intent);    SplashActivity.this.finish();}}, 2500);

4. Modify the manifest file, change the activity on the startup interface to start by default, and set the title bar to be invisible.

<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. example. sinaweibo"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">

<Uses-SDK
Android: minsdkversion = "8"
Android: targetsdkversion = "15"/>

<Application
Android: icon = "@ drawable/ic_launcher"
Android: Label = "@ string/app_name"
Android: theme = "@ Android: style/theme. notitlebar">
<Activity
Android: Name = ". mainactivity"
Android: Label = "@ string/title_activity_main">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>

<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Activity
Android: Name = ". mainactivity1"
Android: Label = "@ string/title_activity_main_activity1">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>

<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>

</Manifest>

In this way, after the application is opened, wait 2.5 seconds to enter the second activity mainactivity.

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.