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

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   io   os   使用   ar   

貼代碼:

<?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則程式正常啟動
 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.