
- layout目录下新建activity_main2.xml
| <?xml version="1.0" encoding="utf-8"?> |
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| xmlns:tools="http://schemas.android.com/tools" |
| android:layout_width="match_parent" |
| android:layout_height="match_parent"> |
| |
| <TextView |
| android:layout_width="wrap_content" |
| android:layout_height="wrap_content" |
| android:text="@string/text2" |
| tools:ignore="MissingConstraints" /> |
| |
| </androidx.constraintlayout.widget.ConstraintLayout> |
| <resources> |
| <string name="app_name">demo</string> |
| |
| |
| <string name="text2">Activity Main 2</string> |
| </resources> |
| package com.example.demo; |
| |
| import android.os.Bundle; |
| import androidx.appcompat.app.AppCompatActivity; |
| |
| public class MainActivity2 extends AppCompatActivity { |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| setContentView(R.layout.activity_main2); |
| } |
| |
| } |
| <activity android:name=".MainActivity2" /> |
- 修改activity_main.xml,编写添加按钮
| <Button |
| android:id="@+id/button" |
| android:layout_width="wrap_content" |
| android:layout_height="wrap_content" |
| android:text="跳转" |
| tools:ignore="MissingConstraints" /> |
| package com.example.demo; |
| |
| import androidx.appcompat.app.AppCompatActivity; |
| import android.content.Intent; |
| import android.os.Bundle; |
| import android.view.View; |
| import android.widget.Button; |
| |
| public class MainActivity extends AppCompatActivity { |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| setContentView(R.layout.activity_main); |
| |
| |
| Button button = findViewById(R.id.button); |
| button.setOnClickListener(new View.OnClickListener() { |
| @Override |
| public void onClick(View v) { |
| Intent intent = new Intent(); |
| intent.setClass(MainActivity.this, MainActivity2.class); |
| startActivity(intent); |
| } |
| }); |
| |
| } |
| } |
- 启动测试

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-07-31 收集数据服务器
2022-07-31 定制监控端点
2022-07-31 指标监控
2022-07-31 前置条件、嵌套测试、参数化测试
2022-07-31 断言
2022-07-31 单元测试
2022-07-31 嵌入式servlet容器