Android項目建立歡迎頁面

來源:互聯網
上載者:User

標籤:

1、製作一張啟動圖片splash.png,放置在res->drawable-hdpi檔案夾中。

2,布局檔案

<span style="font-size:24px;"><?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>
這裡我們把上一步製作的圖片作為啟動介面的背景圖,然後在介面底部顯示當前程式的版本號碼

3、建立SplashActivity,在Oncreate中添加以下代碼:

<span style="font-size:24px;">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>
4、 修改Manifest檔案,將啟動介面Activity改為預設啟動,並且設定標題列不可見。
<span style="font-size:24px;"><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></span>
這樣開啟應用後等待2.5秒就進入第二個activity MainActivity了。

Android項目建立歡迎頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.