signed

QiShunwang

“诚信为本、客户至上”

Android studio实现多个按钮跳转多个页面

2021/5/15 0:50:01   来源:

Android studio实现多个按钮跳转多个页面

Android studio通过多个按钮实现多个页面的跳转

要求下一个页面有音频、图片、单选按钮(RadioGroup)和复选框(CheckBox),还要求有文本输入框(EditText)和Bundle类及应用Intent传递数据。

其共有五个页面,一应俱全,望对其有帮助!

久违的更新,直接来干货,原项目已上传资源库,有问题私信V:mutou88848
在这里插入图片描述

一、实现效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、布局配置文件

1、Text.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    android:background="@drawable/abc">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="67dp"
        android:gravity="center"
        android:text="Android实践示例"
        android:textColor="#FFD700"
        android:textSize="32sp" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="77dp"
        android:src="@drawable/bbb" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="8dp"
        android:text="个人音乐"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="47dp"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="8dp"
        android:text="个人相册"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="47dp"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="8dp"
        android:text="个人信息"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btn4"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="8dp"
        android:text="用户登录"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="133dp"
        android:layout_height="40dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="41dp"
        android:layout_marginRight="8dp"
        android:ems="10"
        android:gravity="center"
        android:text="字典查词"
        android:textColor="#FF5722"
        android:textSize="20sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />


    <EditText
        android:id="@+id/edit"
        android:layout_width="220dp"
        android:layout_height="60dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="41dp"
        android:layout_marginRight="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="请输入你要查询的词组"
        android:textSize="18sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/txt2" />

    <Button
        android:id="@+id/btn5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="查询"
        android:layout_margin="10dp"
        android:background="@drawable/tuh"
        android:textColor="#ffff"
        android:textSize="24sp" />

<!--    <ImageView-->
<!--        android:layout_width="match_parent"-->
<!--        android:layout_height="103dp"-->
<!--        android:src="@drawable/qqqq" />-->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/qqqq"/>


</LinearLayout>
</ScrollView>

2、text1.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="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="80dp">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tt" />
    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="播放音乐"
        android:textSize="24sp" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageButton
            android:id="@+id/Start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/music_play" />
        <ImageButton
            android:id="@+id/Stop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/music_stop" />
        <Button
            android:id="@+id/btn11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="返回"
            android:textSize="24sp"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="3dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>
    </LinearLayout>
</LinearLayout>

3、text2.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="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/abc"
    android:id="@+id/img">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="206dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@drawable/aaaa"
        tools:ignore="MissingConstraints" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="277dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@drawable/dddd"
        tools:ignore="MissingConstraints" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@drawable/qqqq"
        tools:ignore="MissingConstraints" />
    <Button
        android:id="@+id/btn11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回"
        android:textSize="24sp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="40dp"
        android:layout_marginLeft="3dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</LinearLayout>

4、text3.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    tools:context=".MainActivity"
    android:orientation="vertical"
    >
    <!--androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册登记信息!"
            android:textSize="34sp"
            android:textStyle="bold"
            android:layout_gravity="center"
            android:textColor="#F44336"
            android:gravity="center"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="个人信息:"
            android:textColor="#FF9966"
            android:textSize="24sp"
            android:textStyle="bold" />


        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="1.姓名:"

            android:textColor="#254CC4"
            android:textSize="14sp" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:layout_marginTop="10dp"
            android:textSize="14sp"
            android:drawableLeft="@drawable/yonghu"
            android:hint="Name"
            android:drawablePadding="10dp"
            android:inputType="textPersonName"
            />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="32dp"
            android:layout_marginTop="10dp"
            android:text="2.学校:"
            android:textColor="#093A9C"
            android:textSize="14sp"
            />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:layout_marginTop="10dp"
            android:textSize="14sp"
            android:hint="School"
            android:drawablePadding="10dp"
            android:drawableLeft="@drawable/school"
            android:inputType="textPersonName"
            />
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="32dp"
            android:layout_marginTop="10dp"
            android:text="3.电话:"
            android:textColor="#093A9C"
            android:textSize="14sp"
            />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:layout_marginTop="10dp"
            android:textSize="14sp"
            android:hint="Tell"
            android:drawableLeft="@drawable/tel"
            android:drawablePadding="10dp"
            android:inputType="phone"
            />
        <RadioGroup
            android:layout_marginTop="10dp"
            android:id="@+id/rg_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="32dp"
                android:layout_marginTop="10dp"
                android:text="4.性别:"
                android:textColor="#093A9C"
                android:textSize="14sp"
                />

            <RadioButton
                android:id="@+id/rb_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="男生"
                android:layout_marginTop="10dp"
                android:textSize="14sp"
                android:checked="true"
                />
            <RadioButton
                android:id="@+id/rb_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="女生"
                android:textSize="14sp"
                android:layout_marginTop="10dp"
                />
        </RadioGroup>
        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="32dp"
            android:layout_marginTop="10dp"
            android:text="5.是否有以下情况:"
            android:textColor="#093A9C"
            android:textSize="14sp"
            />
        <CheckBox
            android:id="@+id/cb1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="是否是大学生?"
            android:textSize="14sp"
            android:checked="true"
            android:textColor="#9C27B0"
            />

        <CheckBox
            android:id="@+id/cb2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="是否是帅哥?"
            android:textSize="14sp"
            android:textColor="#9C27B0"
            android:layout_marginTop="10dp"
            android:checked="true"
            />
        <CheckBox
            android:id="@+id/cb3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="是否在宿舍学习?"
            android:textSize="14sp"
            android:textColor="#9C27B0"
            android:layout_marginTop="10dp"
            />
        <CheckBox
            android:id="@+id/cb4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="是否打游戏?"
            android:textSize="14sp"
            android:textColor="#9C27B0"
            android:layout_marginTop="10dp"
            />

        <!--Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="提交"
            android:textSize="20dp"
            android:textColor="#AF1237"/-->

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="返回!"
            android:layout_margin="10dp"
            android:background="@drawable/tuh"
            android:textColor="#ffff"
            android:textSize="24sp"

            />
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/www"/>
    </LinearLayout>

</ScrollView>

5、text4.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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:src="@drawable/login_man"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="48dp"/>
    <EditText
        android:id="@+id/login_id"
        android:layout_width="320dp"
        android:layout_height="48dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="48dp"
        android:background="@drawable/login_div_bg"
        android:paddingLeft="8dp"
        android:text="请输入账号" />
    <EditText
        android:id="@+id/login_password"
        android:layout_width="320dp"
        android:layout_height="48dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="16dp"
        android:background="@drawable/login_div_bg"
        android:paddingLeft="8dp"
        android:text="请输入密码" />
    <Button
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textSize="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="155dp"/>
</LinearLayout>

6、text5.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
    <!--    tools:context=".MainActivity">-->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="欢迎来到字典查询"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.508"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.2" />

    <TextView
        android:id="@+id/txt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="24sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintVertical_bias="0.3" />

    <Button
        android:id="@+id/btn6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="248dp"
        android:layout_marginLeft="8dp"
        android:text="返回到字典"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.478"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

三、逻辑控制代码

1、main.java

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
    <!--    tools:context=".MainActivity">-->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="欢迎来到字典查询"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.508"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.2" />

    <TextView
        android:id="@+id/txt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="24sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintVertical_bias="0.3" />

    <Button
        android:id="@+id/btn6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="248dp"
        android:layout_marginLeft="8dp"
        android:text="返回到字典"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.478"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

2、maintext1.java

package com.example.test;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainText1 extends Activity {
    ImageButton Start,Stop;
    MediaPlayer mp;
    Button btn1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text1);

        Start=(ImageButton)findViewById(R.id.Start);
        Stop=(ImageButton)findViewById(R.id.Stop);

        Start.setOnClickListener(new mStart());
        Stop.setOnClickListener(new mStop());

        try {
            mp= MediaPlayer.create(this, R.raw.abc);
            mp.setLooping(true);
        }
        catch(Exception e){
            Toast.makeText(this,"play error", Toast.LENGTH_LONG).show();
        }
    }
    class mStart implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            try {
                if(!mp.isPlaying()){
                    mp.start();
                    Start.setImageResource(R.drawable.music_pause);
                }
                else {
                    mp.pause();
                    Start.setImageResource(R.drawable.music_play);
                }
            }
            catch(Exception e){e.printStackTrace();}
        }
    }
    class mStop implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            mp.reset();
            try {
                mp = MediaPlayer.create(MainText1.this, R.raw.abc);
                mp.setLooping(true);
            }
            catch(Exception e){ e.printStackTrace();}
            Start.setImageResource(R.drawable.music_play);
        }
    }

}

3、maintext2.java

package com.example.test;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;


import androidx.appcompat.app.AppCompatActivity;

import java.util.ResourceBundle;

public class MainText2 extends AppCompatActivity implements View.OnClickListener {
    Button btn11;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text2);

    }

    @Override
    public void onClick(View v) {

    }
}

4.maintext3.java

package com.example.test;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainText3 extends AppCompatActivity implements View.OnClickListener {
    Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text3);

    }

    @Override
    public void onClick(View v) {

    }
}

5、maintext4.java

package com.example.test;
import android.app.Activity;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainText4 extends AppCompatActivity implements View.OnClickListener
{
    Button btn;
    EditText login_id,login_password;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text4);
        login_id = (EditText) findViewById(R.id.login_id);
        login_password = (EditText) findViewById(R.id.login_password);
        btn = (Button) findViewById(R.id.login_button);
        btn.setOnClickListener(this);
    }
    @Override
    public void onClick(View v)
    {
        String  str = login_id.getText()+" "+login_password.getText();
        Toast.makeText(this,str,Toast.LENGTH_LONG).show();
    }

}

6、maintext5.java

package com.example.test;
import android.content.Intent;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainText5 extends AppCompatActivity implements View. OnClickListener{
    Button btn6;
    TextView txt2;
    @Override
    public void onCreate(Bundle bunde) {
        super.onCreate(bunde);
        setContentView(R.layout.text5);
        txt2=(TextView)findViewById(R.id.txt2);
        btn6 = (Button)findViewById(R.id.btn6);
        Bundle bb = this.getIntent().getExtras();
        String str = bb.getString("edit");
        txt2.setText(str);
        btn6.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        Intent intent2 = new Intent();
        intent2.setClass(this, main.class);
        startActivityForResult(intent2,0);//返回前一页面界面
    }
}

四、配置信息文件AndroidMAnifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Test">
        <activity android:name=".main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainText1"></activity>
        <activity android:name=".MainText2"></activity>
        <activity android:name=".MainText3"></activity>
        <activity android:name=".MainText4"></activity>
        <activity android:name=".MainText5"></activity>
    </application>

</manifest>

在这里插入图片描述