Android 應(yīng)用啟動歡迎界面廣告
創(chuàng)新互聯(lián)是專業(yè)的德清網(wǎng)站建設(shè)公司,德清接單;提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行德清網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
0.寫在前面
在這篇教程中來實現(xiàn)一個類似于微信的的延遲3秒再進入主界面的效果。
1.項目準備
先新建一個空的android項目。里面只自帶一個MainActivity,首先我們再新建一個Activity叫做WelcomeActivity繼承自Activity。
Activity代碼如下:
//package在此省略,根據(jù)實際自行添加 import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; /** * Created by HUPENG on 2016/9/21. */ public class WelcomeActivity extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); } }
布局文件代碼如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/imageView" android:layout_gravity="center_horizontal" android:src="@mipmap/welcome"/> <!--android src屬性指定imageView里面要顯示的資源文件的來源路徑,也就是在歡迎界面顯示的圖片,在這里我已經(jīng)預(yù)先上傳了一張圖片了--> </LinearLayout>
修改清單文件AndroidManifest.xml
聲明WelcomeActivity以及修改Activity的啟動順序,由MainActivity改成WelcomeActivity
原來的xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="supershare.android.hupeng.me.supershare"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
修改成
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="supershare.android.hupeng.me.supershare"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".WelcomeActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name=".MainActivity"> </activity> </application> </manifest>
至此項目的布局已經(jīng)完成了,現(xiàn)在來完成跳轉(zhuǎn)部分源碼
在這里用到的核心函數(shù)為
Handler.sendEmptyMessageDelayed
主要用來發(fā)送延遲消息
首先新建一個消息處理對象,負責(zé)發(fā)送與處理消息
private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); } };
在handleMessage方法中處理消息,在這里接收到消息不做復(fù)雜處理以后直接執(zhí)行跳轉(zhuǎn)操作
貼上WelcomeActivity全部代碼
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.Nullable; import android.view.Window; import android.view.WindowManager; /** * Created by HUPENG on 2016/9/21. */ public class WelcomeActivity extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); //隱藏標題欄以及狀態(tài)欄 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); /**標題是屬于View的,所以窗口所有的修飾部分被隱藏后標題依然有效,需要去掉標題**/ requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_welcome); handler.sendEmptyMessageDelayed(0,3000); } private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { getHome(); super.handleMessage(msg); } }; public void getHome(){ Intent intent = new Intent(WelcomeActivity.this, MainActivity.class); startActivity(intent); finish(); } }
2.總結(jié)
在這里主要利用了android.os.Handler的消息的延遲發(fā)送以及處理。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
網(wǎng)站欄目:Android應(yīng)用啟動歡迎界面廣告的實現(xiàn)實例
網(wǎng)站路徑:http://chinadenli.net/article26/gidjjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、商城網(wǎng)站、網(wǎng)站導(dǎo)航、企業(yè)網(wǎng)站制作、品牌網(wǎng)站制作、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)