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

测试

布局技巧


相关推荐
2501_915918411 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
skiy1 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
小小小点2 小时前
Android四大常用布局详解与实战
android
bandaostart2 小时前
VsCode+Cmake使用说明
ide·vscode·编辑器
freshman_y2 小时前
个人VSCode一些配置记录
ide·vscode·编辑器
MinQ3 小时前
binder和socket区别及原理
android
Ehtan_Zheng3 小时前
Jetpack Compose 中绘制发光边框的多种方式
android
智塑未来3 小时前
像素蛋糕安卓版 AI 专业修图全场景输出高清成片
android·人工智能
我是人✓4 小时前
IDEA(2017.3 x64)的安装及使用
java·ide·intellij-idea
陆业聪5 小时前
让 Android 里的 AI 真正「干活」:Function Calling 工程实现全解
android·ai·kotlin