Android App啟動(dòng)圖啟動(dòng)界面(Splash)的簡(jiǎn)單實(shí)現(xiàn)代碼
第一步:創(chuàng)建一個(gè)Activity
第二步:創(chuàng)建一個(gè)新的Activity 命名為Splash
new -> Activity -> Empty Activity
p>第三步:將準(zhǔn)備好的啟動(dòng)圖片放到drawable目錄下,并修改Splash的xml布局文件,如下圖所示
第四步:修改SplashActivity中的代碼如下
import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.WindowManager;public class Splash extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate( savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隱藏狀態(tài)欄 getSupportActionBar().hide();//隱藏標(biāo)題欄 setContentView(R.layout.activity_splash); Thread myThread=new Thread(){//創(chuàng)建子線程 @Override public void run() { try{ sleep(5000);//使程序休眠五秒 Intent it=new Intent(getApplicationContext(),MainActivity.class);//啟動(dòng)MainActivity startActivity(it); finish();//關(guān)閉當(dāng)前活動(dòng) }catch (Exception e){ e.printStackTrace(); } } }; myThread.start();//啟動(dòng)線程}}
注 意
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getSupportActionBar().hide();
需要在 setContentView(R.layout.activity_splash);
之前執(zhí)行
第五步:修改配置文件AndroidManifest中的代碼
將上述代碼的intent filter標(biāo)簽移動(dòng)到name為.Splash的Activity標(biāo)簽下(將啟動(dòng)頁(yè)面修改為SplashActivity),如下圖
好了,現(xiàn)在大功告成了,快運(yùn)行代碼試試效果怎么樣
總結(jié)
到此這篇關(guān)于Android App啟動(dòng)圖啟動(dòng)界面(Splash)的簡(jiǎn)單實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Android App啟動(dòng)圖啟動(dòng)界面(Splash)的簡(jiǎn)單實(shí)現(xiàn)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Java鏈表元素查找實(shí)現(xiàn)原理實(shí)例解析2. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法3. SpringBoot+TestNG單元測(cè)試的實(shí)現(xiàn)4. Springboot 全局日期格式化處理的實(shí)現(xiàn)5. 利用CSS制作3D動(dòng)畫(huà)6. Python+unittest+requests 接口自動(dòng)化測(cè)試框架搭建教程7. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程8. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼9. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))10. 一款功能強(qiáng)大的markdown編輯器tui.editor使用示例詳解
