【Android Studio】Intent实现两个Activity页面的跳转(基于Empty View Activity)

文章目录

为什么使用EmptyViewActivity而不是EmptyActivity

因为笔者使用的AndroidStudio版本比较新,经过测试从水母版开始EmptyActivity就不再支持选择JAVA语言,本次实验使用的AndroidStudio版本如下图所示:

准备工作:创建EmptyViewActivity项目


最原始项目结构如下:

准备工作:新建SecondActivity


如下图所示,会多出两个文件:一个是Activity文件,另一个是布局文件

调试一下原始项目


添加button

给MainActivity设置button



写跳转方法

java 复制代码
    public void toSecond(View view) {
        Intent intent =new Intent();
        intent.setClass(this,SecondActivity.class);
        startActivity(intent);
    }

测试

布局技巧


相关推荐
火柴就是我13 分钟前
Flutter 混合模式下:saveLayer 混合注意点
android·flutter
Mintopia33 分钟前
🎙️ React Native(RN)语音输入场景全解析
android·react native·aigc
centor42 分钟前
国际版 UnitySetup-Android-Support 安装 Mac 设备
android·macos
hi0_61 小时前
vibe coding 开发软件(一) 模型选择和agent简单使用
ide·个人开发·visual studio
城东米粉儿1 小时前
compose 中的附带效应笔记一
android
惊讶的猫1 小时前
vscode+conda
ide·vscode·conda
谧小夜1 小时前
Visual Studio Code中实现Go语言自动导包教程
ide·vscode·golang
STCNXPARM1 小时前
Android14显示系统 - VSYNC机制
android·surfaceflinger·vsync
say_fall1 小时前
C++ 类与对象易错点:初始化列表顺序 / 静态成员访问 / 隐式类型转换
android·java·开发语言·c++
落羽凉笙2 小时前
Python基础(4)| 详解程序选择结构:单分支、双分支与多分支逻辑(附代码)
android·服务器·python