【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);
    }

测试

布局技巧


相关推荐
我不会插花弄玉1 小时前
7.函数【由浅入深-MySQL】
android·数据库·mysql
vilya2 小时前
手机端 Agent 怎么动起来:Kotlin 与 Python 之间的桥
android·agent
高晶2 小时前
Android 新手实战:从零搭建 WebRTC 在线直播系统
android·程序员
alexhilton2 小时前
为什么你的 LazyColumn 仍然卡顿
android·kotlin·android jetpack
>Andre<3 小时前
系统架构全景
android
hai_android8 小时前
Android 嵌套滑动冲突:内部拦截 vs 外部拦截实战
android·android studio·android jetpack
木子欢儿9 小时前
Zabbix 7.4 Alpine 版 Docker Compose 部署
android·运维·docker·容器·zabbix
素师良码10 小时前
第9篇:Android驱动踩坑实录:DSI RX FIFO前置脏0、数据错位复盘
android
夜雪一千11 小时前
如何在MySQL中实现字段级加密
android·数据库·mysql
夜雪一千11 小时前
MySQL 如何存储经纬度坐标:选型、建表、空间查询实战
android·mysql·adb