Android欢迎页面2秒钟后自动跳转到主页面

页面跳转

一、功能介绍

打开APP先进入欢迎页面,2秒钟后自动进入主页面

二、项目结构分析

三、详细代码

1、WelcomeActivity.java

package com.xingyun.shoopingmail4;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.xingyun.shoopingmail4.activity.MainActivity;

public class WelcomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        //两秒钟进入主页面
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //执行在主线程
                //启动主页面
                startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
                //关闭当前页面
                finish();
            }
        },2000);
    }
}

2、MainActivity.java

package com.xingyun.shoopingmail4.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.xingyun.shoopingmail4.R;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @Bind(R.id.frameLayout)
    FrameLayout frameLayout;
    @Bind(R.id.rg_main)
    RadioGroup rgMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        rgMain.check(R.id.rb_home);
    }
}

3、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xingyun.shoopingmail4">

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        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=".activity.MainActivity"></activity>
    </application>

</manifest>

4、activity_mainjava

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    tools:context=".activity.MainActivity">

    <!---->
    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <!---->
    <RadioGroup
        android:id="@+id/rg_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/home_bottom_parent_bg"
        android:orientation="horizontal">

        <!---->
        <RadioButton
            android:id="@+id/rb_home"
            style="@style/MainButtonStyle"
            android:drawableTop="@drawable/home_button_selector"
            android:text="首页" />

        <RadioButton
            android:id="@+id/rb_type"
            style="@style/MainButtonStyle"
            android:drawableTop="@drawable/type_button_selector"
            android:text="分类" />

        <!---->
        <RadioButton
            android:id="@+id/rb_community"
            style="@style/MainButtonStyle"
            android:drawableTop="@drawable/community_button_selector"
            android:paddingTop="10dp"
            android:text="发现" />

        <RadioButton
            android:id="@+id/rb_cart"
            style="@style/MainButtonStyle"
            android:drawableTop="@drawable/cart_button_selector"
            android:text="购物车" />

        <RadioButton
            android:id="@+id/rb_user"
            style="@style/MainButtonStyle"
            android:drawableTop="@drawable/user_button_selector"
            android:text="个人中心" />
    </RadioGroup>

</LinearLayout>

5、activity_welcome.java

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_welcome"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#ffffff"
    tools:context=".WelcomeActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/logo" />
</RelativeLayout>

6、build.gradle

apply plugin: ‘com.android.application‘

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.xingyun.shoopingmail4"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
        }
    }
}

dependencies {
    implementation fileTree(dir: ‘libs‘, include: [‘*.jar‘])
    implementation ‘com.android.support:appcompat-v7:28.0.0‘
    implementation ‘com.android.support.constraint:constraint-layout:1.1.3‘
    testImplementation ‘junit:junit:4.12‘
    androidTestImplementation ‘com.android.support.test:runner:1.0.2‘
    androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2‘
    implementation ‘com.jakewharton:butterknife:7.0.1‘
}

四、运行结果

————>2秒钟后自动跳转到下面的界面:



原文地址:http://blog.51cto.com/doublelinux/2340085

时间: 2024-08-09 11:07:24

Android欢迎页面2秒钟后自动跳转到主页面的相关文章

JS实现倒计时网页自动跳转(如404页面经常使用到的)

在web前端设计中,我们经常会遇到需要实现页面倒计时跳转的功能,例如在404页面中也会经常使用到此功能,那么如何实现呢,其实实现方法很简单,实现代码如下:<title>JS倒计时网页自动跳转代码</title> <script language="JavaScript" type="text/javascript"> function delayURL(url) { var delay = document.getElementB

用js在网页上完成倒计时3秒后自动跳转到另一个页面

<body> <div id="time"></div> <a href="#" onclick="stop()">停止</a> <script type="text/javascript"> var i=3; function changeTime(){ document.getElementById("time").innerHTM

js实现网页多少秒后自动跳转到指定网址

在网上搜了一下,关于这个技术处理有多种方法,我只记下我在视频里学到的三种: 1.用一个response.sendRedirect("目标页面.jsp\.htm");实现直接跳转: 2.有时我们需要有点提示,比如“x秒后自动跳转,若没有跳转,请点击此处”,则可以在myeclipse中调用Snippets中的Delay Go To URL.会自动生成如下代码: 代码如下: <script language="JavaScript1.2" type="te

(转)完美解决 Android WebView 文本框获取焦点后自动放大有关问题

完美解决 Android WebView 文本框获取焦点后自动放大问题 前几天在写一个项目时,要求在项目中嵌入一个WebView 本来很快就完成了,测试也没有问题.但发给新加坡时,他们测试都会出现文本框聚焦时,网页面会放大(他们用三星手机测试的) 网上查了好久参考他的方法加上去测试 http://www.cppblog.com/guojingjia2006/archive/2012/12/18/196429.html 下面我将原文copy过来 **************************

完美解决 Android WebView 文本框获取焦点后自动放大问题

前几天在写一个项目时,要求在项目中嵌入一个WebView 本来很快就完成了,测试也没有问题.但发给新加坡时,他们测试都会出现文本框聚焦时,网页面会放大(他们用三星手机测试的) 网上查了好久参考他的方法加上去测试 http://www.cppblog.com/guojingjia2006/archive/2012/12/18/196429.html 下面我将原文copy过来 **************************************************************

HTML页面-------3秒之后自动跳转的3种常用的实现方式

在练习中,我们常常遇到一种问题就是,怎么实现页面N秒之后自动跳转呢? 我自己遇到问题和查找资料,总结了3个方法 方法1: 最简单的一种:直接在前面<head>里面添加代码: <span style="font-size:18px;"> </span><span style="font-size:24px;"><meta http-equiv="refresh" content="3;

session过期后自动跳转到登陆页

项目需要做一个自动登出的功能,查询了网上的资料,一开始准备用session监听做,按照下面方式配置监听器 1.在项目的web.xml文件中添加如下代码: <!--添加Session监听器--> <listener> <listener-class> 监听器路径 </listener-class> </listener> 2.编写java类. public class SessionListener implements HttpSessionLi

计时3秒后自动跳转到登录页

<script> //计时3秒后自动跳转到登录页 var i = 3; var time_out; time_out = setInterval("time()", 800); function time() { if(i == 0){ window.location.href = "/user/login"; clearInterval(time_out); } document.getElementById("time").inn

jBox如何实现3秒后自动跳转

首先要调用window的定时器,里面有一个函数,如下: $.jBox.tip("注册成功,3秒后自动跳转--", 'success'); window.setTimeout(function () { window.location.href = document.getElementById('strBackUrl').value }, 3000);