国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)歡迎界面停留3秒效果

2019-10-22 18:15:23
字體:
供稿:網(wǎng)友

0.寫在前面

在這篇教程中來實(shí)現(xiàn)一個類似于微信的的延遲3秒再進(jìn)入主界面的效果。

1.項(xiàng)目準(zhǔn)備

先新建一個空的android項(xiàng)目。里面只自帶一個MainActivity,首先我們再新建一個Activity叫做WelcomeActivity繼承自Activity。

Activity代碼如下:

//package在此省略,根據(jù)實(shí)際自行添加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>

至此項(xiàng)目的布局已經(jīng)完成了,現(xiàn)在來完成跳轉(zhuǎn)部分源碼

在這里用到的核心函數(shù)為

Handler.sendEmptyMessageDelayed

主要用來發(fā)送延遲消息

首先新建一個消息處理對象,負(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);    //隱藏標(biāo)題欄以及狀態(tài)欄    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        WindowManager.LayoutParams.FLAG_FULLSCREEN);    /**標(biāo)題是屬于View的,所以窗口所有的修飾部分被隱藏后標(biāo)題依然有效,需要去掉標(biāo)題**/    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ā)送以及處理。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 莫力| 高唐县| 赣榆县| 积石山| 仲巴县| 高青县| 琼海市| 安岳县| 汉阴县| 峨山| 大田县| 鹤岗市| 高台县| 新龙县| 红安县| 芦溪县| 扎兰屯市| 长白| 涿州市| 鸡西市| 华安县| 柳江县| 通化县| 凤台县| 永修县| 华安县| 池州市| 三门县| 德清县| 中方县| 平武县| 周宁县| 北流市| 威远县| 福安市| 郴州市| 湘乡市| 西充县| 吉木萨尔县| 辉县市| 个旧市|