簡單實現(xiàn)Android應用的啟動頁
前言:
平時打開手機的應用時,會跳出來3秒鐘的廣告后,再進入應用。今天我們就來簡單實現(xiàn)一下引導頁的功能。
1、首先,新建一個activity頁面,命名:SplashActivity
在 activity_splash.xml中添加啟動頁內(nèi)容,我這里添加了一個圖片(圖片放在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文件中,將啟動頁狀態(tài)欄和標題欄隱藏,并設置啟動頁顯示時間為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);
//隱藏標題欄
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();//啟動線程
}
}2、在AndroidManifest.xml文件中,設置啟動頁為.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、我這里將應用圖標改為自己的圖片了,你們根據(jù)自己需要(不改也行的),代碼如下:

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

