可能是Android最简单的欢迎页面实现

  • 例如QQ的经典欢迎页面
    这里写图片描述

前言

目前市面上的大多数 App 都有一个欢迎页面,有如下优点:
1. 利用展示欢迎页面的时间来加载数据
2. 展示品牌设计风格

步骤

  • 创建布局文件
  • 设置欢迎页面
  • 延时 2S 跳转

创建布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    tools:context="com.example.ethan.imtest.controller.activity.SplashActivity">

    <ImageView
        android:id="@+id/splashview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/atguigu_logo" />
</android.support.constraint.ConstraintLayout>

设置欢迎界面


        <activity android:name=".controller.activity.SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

延时 2s 跳转

使用 Handler 执行延时2s的操作

//延时两秒钟
    private  Handler handler=new Handler(){

        public void handleMessage(Message msg) {

            //如果当前activity已经退出,不对消息进行处理
             if (isFinishing()){
                return;
             }
             toMainOrLogin();
        }
    };


    //选择进入主页面还是登录页面
    protected void toMainOrLogin(){
       new Thread(new Runnable() {
           @Override
           public void run() {
                   //如果登陆过,进入主界面
               if (EMClient.getInstance().isLoggedInBefore()){
                   Intent intent = new Intent(SplashActivity.this,MainActivity.class);
                   startActivity(intent);
               }
               else {
                   //没有登录过,进入登录界面
                   Intent intent=new Intent(SplashActivity.this,LoginActivity.class);
                   startActivity(intent);
               }

               finish();
           }
       }).start();

    }

    @Override
    protected void  onDestroy(){
        //销毁消息
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }

实现效果

Markdown

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值