簡(jiǎn)單實(shí)現(xiàn)Android應(yīng)用的啟動(dòng)頁(yè)
前言:
平時(shí)打開(kāi)手機(jī)的應(yīng)用時(shí),會(huì)跳出來(lái)3秒鐘的廣告后,再進(jìn)入應(yīng)用。今天我們就來(lái)簡(jiǎn)單實(shí)現(xiàn)一下引導(dǎo)頁(yè)的功能。
1、首先,新建一個(gè)activity頁(yè)面,命名:SplashActivity
在 activity_splash.xml中添加啟動(dòng)頁(yè)內(nèi)容,我這里添加了一個(gè)圖片(圖片放在drawable文件下),代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:background="@drawable/zhz"
tools:context=".SplashActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/zhz"></ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>在java文件中,將啟動(dòng)頁(yè)狀態(tài)欄和標(biāo)題欄隱藏,并設(shè)置啟動(dòng)頁(yè)顯示時(shí)間為3秒。
SplashActivity.java代碼如下:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隱藏狀態(tài)欄
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//隱藏標(biāo)題欄
getSupportActionBar().hide();
setContentView(R.layout.activity_splash);
//創(chuàng)建子線程
Thread mThread=new Thread(){
@Override
public void run() {
super.run();
try {
sleep(3000);//使程序休眠3秒
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
}catch (Exception e){
e.printStackTrace();
}
}
};
mThread.start();//啟動(dòng)線程
}
}2、在AndroidManifest.xml文件中,設(shè)置啟動(dòng)頁(yè)為.SplashActivity,代碼如下:

<activity android:name=".StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>3、我這里將應(yīng)用圖標(biāo)改為自己的圖片了,你們根據(jù)自己需要(不改也行的),代碼如下:

這樣就完成了所有步驟了,運(yùn)行一下試試吧!
到此這篇關(guān)于簡(jiǎn)單實(shí)現(xiàn)Android應(yīng)用的啟動(dòng)頁(yè)的文章就介紹到這了,更多相關(guān)Android啟動(dòng)頁(yè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android中的windowSoftInputMode屬性詳解
這篇文章主要介紹了Android中的windowSoftInputMode屬性詳解,本文對(duì)windowSoftInputMode的9個(gè)屬性做了詳細(xì)總結(jié),需要的朋友可以參考下2014-10-10
Android開(kāi)發(fā)入門(mén)環(huán)境快速搭建實(shí)戰(zhàn)教程
最近想重新學(xué)習(xí)下Android,學(xué)習(xí)之前開(kāi)發(fā)環(huán)境的搭建是個(gè)首先要解決的問(wèn)題,所以下面這篇文章主要給大家介紹了Android開(kāi)發(fā)環(huán)境搭建的相關(guān)資料,文中將實(shí)現(xiàn)的步驟一步步介紹的非常詳細(xì),需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11
基于Android Service 生命周期的詳細(xì)介紹
本篇文章小編為大家介紹,基于Android Service 生命周期的詳解。需要的朋友參考下2013-04-04
android系統(tǒng)在靜音模式下關(guān)閉camera拍照聲音的方法
本文為大家詳細(xì)介紹下android系統(tǒng)如何在靜音模式下關(guān)閉camera拍照聲音,具體的實(shí)現(xiàn)方法如下,感興趣的朋友可以參考下哈2013-07-07
Android studio實(shí)現(xiàn)左右滑動(dòng)切換圖片
這篇文章主要為大家詳細(xì)介紹了Android studio實(shí)現(xiàn)左右滑動(dòng)切換圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android自定義view利用PathEffect實(shí)現(xiàn)動(dòng)態(tài)效果
這篇文章主要為大家詳細(xì)介紹了Android自定義view利用PathEffect實(shí)現(xiàn)動(dòng)態(tài)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05

