【Android】Mac下Android Studio設定App啟動頁

來源:互聯網
上載者:User

標籤:配置   extend   delay   bundle   main   handler   final   star   img   

先將啟動頁放到項目資源中,圖片一般是1080*1920的jpg。
建立一個activity,

建立成功之後,開啟剛剛建立的activity,來進行代碼的編寫:

public class BZLaunchActivity extends AppCompatActivity {    private  final int SPLASH_DISPLAY_LENGHT = 2000;//兩秒後進入系統,時間可自行調整    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_bzlaunch);                //在BZLaunchActivity停留2秒然後進入BZLaunchActivity        new android.os.Handler().postDelayed(new Runnable() {            @Override            public void run() {                Intent mainIntent = new Intent(BZLaunchActivity.this,MainActivity.class);                BZLaunchActivity.this.startActivity(mainIntent);                BZLaunchActivity.this.finish();            }        },SPLASH_DISPLAY_LENGHT);    }}

然後去xml設定檔裡畫介面,設定檔在res/layout與建立時layout同名的的xml檔案,代碼如下:

<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".BZLaunchActivity">    <ImageView        android:id="@+id/imageView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        //讓圖片全螢幕顯示        android:scaleType="fitXY"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent"        //啟動頁圖片        app:srcCompat="@mipmap/zqq_launch" /></android.support.constraint.ConstraintLayout>

如果android:scaleType="fitXY"不設定,可能出現啟動頁圖片不全屏的情況。
最後要去AndroidManifest.xml檔案中修改一下啟動頁的activity的位置,未修改之前,MainActivity是在前面的,這個時候運行App,發現並沒有啟動頁,我們需要把啟動頁的activity調到MainActivity的前面,也就是:

        <activity android:name=".BZLaunchActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity android:name=".MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>

好了,完成上面這些,再運行App,就會看到啟動頁了。

【Android】Mac下Android Studio設定App啟動頁

相關文章

聯繫我們

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