3.13
所花时间:1.5小时
代码量:51
博客篇:1
了解到的知识点
页面的跳转和返回
跳转使用startActivity(Intent)
返回使用finish
跳转:
package com.example.test1; import android.content.Intent; import android.os.Bundle; import android.view.View; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.bt1).setOnClickListener(this); } @Override public void onClick(View v) { startActivity(new Intent(this, MainActivity2.class)); } }
返回:
package com.example.test1; import android.os.Bundle; import android.view.View; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity2 extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); findViewById(R.id.bt_back).setOnClickListener(this); } @Override public void onClick(View v) { finish(); } }