Android開發學習筆記-splash畫面的顯示


貼代碼:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.frank.mobilesafe"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
           
        </activity>
        <activity
            android:name=".SplashActivity"
          android:theme="@android:style/Theme.NoTitleBar"
            android:label="@string/title_activity_splash" >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

處理類:

package com.frank.mobilesafe;


import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄
        setContentView(R.layout.activity_splash);
        TextView tv_version = (TextView) findViewById(R.id.tv_version);
        tv_version.setText(getVersion());
    }

    protected String getVersion() {
        String versionStr = "";
        PackageManager packManger = getPackageManager();
        try {
            PackageInfo info = packManger.getPackageInfo(getPackageName(), 0);
            versionStr = info.versionName;//獲得版本號
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            versionStr = "";
            e.printStackTrace();
        }
        return versionStr;
        
    }
}

配置文件:

 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
           
        </activity>
        <activity
            android:name=".SplashActivity"
          android:theme="@android:style/Theme.NoTitleBar"
            android:label="@string/title_activity_splash" >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

總結:

1、在設置splash畫面顯示的時候,最初以為是使用ImageView,最后了解才知道是使用的android:background="@drawable/luncher_bg"

2、新技術主要就是使用packmanger類讀入關於版本的一些信息了

3、在去除標題的時候在配置文件中加入 android:theme="@android:style/Theme.NoTitleBar"之后程序在啟動的時候就報錯,最后看logcat順着流程走才發現原來

Activity默認繼承的是ActionBarActivity類,將其改為Activity則程序正常啟動
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM