android 每隔2秒执行_Android欢迎页面2秒钟后自动跳转到主页面

2023-11-11 23:31

本文主要是介绍android 每隔2秒执行_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

package="com.xingyun.shoopingmail4">

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">

4、activity_mainjava

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">

android:id="@+id/frameLayout"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1" />

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">

android:id="@+id/rb_home"

style="@style/MainButtonStyle"

android:drawableTop="@drawable/home_button_selector"

android:text="首页" />

android:id="@+id/rb_type"

style="@style/MainButtonStyle"

android:drawableTop="@drawable/type_button_selector"

android:text="分类" />

android:id="@+id/rb_community"

style="@style/MainButtonStyle"

android:drawableTop="@drawable/community_button_selector"

android:paddingTop="10dp"

android:text="发现" />

android:id="@+id/rb_cart"

style="@style/MainButtonStyle"

android:drawableTop="@drawable/cart_button_selector"

android:text="购物车" />

android:id="@+id/rb_user"

style="@style/MainButtonStyle"

android:drawableTop="@drawable/user_button_selector"

android:text="个人中心" />

5、activity_welcome.java

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">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:src="@drawable/logo" />

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'

}

四、运行结果

4b941d6c393b7d9de77460fa11e72756.png

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

d82a7634f010ba72318f033b5c2e9212.png

这篇关于android 每隔2秒执行_Android欢迎页面2秒钟后自动跳转到主页面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/393550

相关文章

MyBatis Plus实现时间字段自动填充的完整方案

《MyBatisPlus实现时间字段自动填充的完整方案》在日常开发中,我们经常需要记录数据的创建时间和更新时间,传统的做法是在每次插入或更新操作时手动设置这些时间字段,这种方式不仅繁琐,还容易遗漏,... 目录前言解决目标技术栈实现步骤1. 实体类注解配置2. 创建元数据处理器3. 服务层代码优化填充机制详

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

Java实现远程执行Shell指令

《Java实现远程执行Shell指令》文章介绍使用JSch在SpringBoot项目中实现远程Shell操作,涵盖环境配置、依赖引入及工具类编写,详解分号和双与号执行多指令的区别... 目录软硬件环境说明编写执行Shell指令的工具类总结jsch(Java Secure Channel)是SSH2的一个纯J

深入浅出Spring中的@Autowired自动注入的工作原理及实践应用

《深入浅出Spring中的@Autowired自动注入的工作原理及实践应用》在Spring框架的学习旅程中,@Autowired无疑是一个高频出现却又让初学者头疼的注解,它看似简单,却蕴含着Sprin... 目录深入浅出Spring中的@Autowired:自动注入的奥秘什么是依赖注入?@Autowired

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

基于Redis自动过期的流处理暂停机制

《基于Redis自动过期的流处理暂停机制》基于Redis自动过期的流处理暂停机制是一种高效、可靠且易于实现的解决方案,防止延时过大的数据影响实时处理自动恢复处理,以避免积压的数据影响实时性,下面就来详... 目录核心思路代码实现1. 初始化Redis连接和键前缀2. 接收数据时检查暂停状态3. 检测到延时过

python 线程池顺序执行的方法实现

《python线程池顺序执行的方法实现》在Python中,线程池默认是并发执行任务的,但若需要实现任务的顺序执行,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录方案一:强制单线程(伪顺序执行)方案二:按提交顺序获取结果方案三:任务间依赖控制方案四:队列顺序消

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

SpringBoot实现RSA+AES自动接口解密的实战指南

《SpringBoot实现RSA+AES自动接口解密的实战指南》在当今数据泄露频发的网络环境中,接口安全已成为开发者不可忽视的核心议题,RSA+AES混合加密方案因其安全性高、性能优越而被广泛采用,本... 目录一、项目依赖与环境准备1.1 Maven依赖配置1.2 密钥生成与配置二、加密工具类实现2.1