需要实现的效果
- 要求移动应用中有3个活动:MainActivity ,FirstActivity和SecondActivity。
- 在MainActivity中利用Button控件,自定义一个按钮菜单,可以从主活动跳转到其他活动中,并可以从其他活动跳转返回到主活动。其中一个按钮菜单是“退出”菜单项,可以直接从该移动应用退出。
- 定义一个Student类,属性由姓名name: String和birthday:LocalDate, 要求将一个学生对象(张三,1999-02-23), 从活动MainActivity传递到FirstActivity, 并在FirstActivity中显示该对象信息。
- 运行结果如图
1. 添加FirstActivity/SecondActivity活动以及Student类
- xml布局文件
(1)activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="400dp"
android:layout_height="51dp"
android:text="菜单页面"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.326"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.008" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="63dp"
android:onClick="skipToPageOne"
android:text="跳到第一个页面"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="140dp" />