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

测试

布局技巧


相关推荐
eric*168830 分钟前
Android15 enableEdgeToEdge 全面屏沉浸式体验
android·edgetoedge
小智社群2 小时前
小米安卓真机ADB对硬件操作
android·adb
嗷o嗷o2 小时前
Android BLE 为什么连上了却收不到数据
android
pengyu2 小时前
【Kotlin 协程修仙录 · 炼气境 · 后阶】 | 划定疆域:CoroutineScope 与 Android 生命周期的绑定艺术
android·kotlin
朝星2 小时前
Android开发[5]:组件化之路由+注解
android·kotlin
随遇丿而安2 小时前
Android全功能终极创作
android
随遇丿而安3 小时前
第1周:别小看 `TextView`,它其实是 Android 页面里最常被低估的组件
android
此生只爱蛋6 小时前
【vscode环境配置心得】C++版
c++·ide·vscode
summerkissyou19876 小时前
Android-基础-SystemClock.elapsedRealtime和System.currentTimeMillis区别
android
ian4u6 小时前
车载 Android C++ 完整技能路线:从基础到进阶
android·开发语言·c++