日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【Android学习笔记】设置App启动页

發(fā)布時間:2025/7/14 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android学习笔记】设置App启动页 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

先將啟動頁放到項(xiàng)目資源中,圖片一般是1080*1920的jpg。
新建一個activity,如圖:

創(chuàng)建成功之后,打開剛剛創(chuàng)建的activity,來進(jìn)行代碼的編寫:

public class BZLaunchActivity extends AppCompatActivity {private final int SPLASH_DISPLAY_LENGHT = 2000;//兩秒后進(jìn)入系統(tǒng),時間可自行調(diào)整@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_bzlaunch);//在BZLaunchActivity停留2秒然后進(jìn)入BZLaunchActivitynew android.os.Handler().postDelayed(new Runnable() {@Overridepublic void run() {Intent mainIntent = new Intent(BZLaunchActivity.this,MainActivity.class);BZLaunchActivity.this.startActivity(mainIntent);BZLaunchActivity.this.finish();}},SPLASH_DISPLAY_LENGHT);} }

然后去xml配置文件里畫界面,配置文件在res/layout與創(chuàng)建時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"><ImageViewandroid: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"不設(shè)置,可能出現(xiàn)啟動頁圖片不全屏的情況。
最后要去AndroidManifest.xml文件中修改一下啟動頁的activity的位置,未修改之前,MainActivity是在前面的,這個時候運(yùn)行App,發(fā)現(xiàn)并沒有啟動頁,我們需要把啟動頁的activity調(diào)到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>

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

總結(jié)

以上是生活随笔為你收集整理的【Android学习笔记】设置App启动页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。