Android欢迎界面的创建方法

来源:互联网 发布:淘宝代购店实体店 编辑:程序博客网 时间:2024/06/05 08:48

1、制作一张启动图片splash.png,放置在res->drawable-hdpi文件夹中。
2、新建布局文件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>

 <span style="font-family: 微软雅黑, sans-serif, Arial, 宋体, sans-serif;">这里我们把上一步制作的图片作为启动界面的背景图,然后在界面底部显示当前程序的版本号。</span>

3、新建SplashActivity,在Oncreate中添加以下代码:

<span style="font-family: KaiTi_GB2312; font-size: 12px;">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);</span><span style="font-family: 'Courier New', Courier, monospace;"></span>

4、 修改Manifest文件,将启动界面Activity改为默认启动,并且设置标题栏不可见。 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sinaweibo"
    android:versionCode="1"
    android:versionName="1.0" >


    <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>

这样打开应用后等待2.5秒就进入第二个activity MainActivity了。

版权声明:本文为博主原创文章,未经博主允许不得转载。

0 0