第四章活动Activity-4.1 Activity的启动和结束

1.创建新的模块:
https://note.youdao.com/yws/public/resource/27eebd0325090d0fc737b364d31e03b5/xmlnote/2C8A6BF92DB84DD8A1045774C33BF580/34103

知识点:
https://note.youdao.com/yws/public/resource/27eebd0325090d0fc737b364d31e03b5/xmlnote/6E3B102F75C6448692A983F5B49E068C/34107

创建活动页面:ActStartActivity
布局文件activity_act_start.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center">

    <Button

        android:id="@+id/btn_act_next"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="跳到下个页面" />

 

</LinearLayout>

创建活动页面:ActFinishActivity
布局文件 activity_act_finish.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

    <ImageView

        android:id="@+id/iv_back"

        android:layout_width="40dp"

        android:layout_height="40dp"

        android:padding="5dp"

        android:src="@drawable/ic_back" />

 

    <Button

        android:id="@+id/btn_finish"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:gravity="center"

        android:text="完成" />

 

    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="按返回键,或者点击左上角的箭头图标,或者点击上面的完成按钮,均可关闭当前页面、返回上个页面" />

 

 

</LinearLayout>

其中添加 图片资源文件:
https://note.youdao.com/yws/public/resource/27eebd0325090d0fc737b364d31e03b5/xmlnote/733C7E9BD3FC40A9991C9DDAF28F5AA8/34122

后台代码 ActStartActivity

package com.example.chapter04;

 

import androidx.appcompat.app.AppCompatActivity;

 

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

 

public class ActStartActivity extends AppCompatActivity implements View.OnClickListener {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_act_start);

        findViewById(R.id.btn_act_next).setOnClickListener(this);

    }

 

    @Override

    public void onClick(View v) {

        // 1.在Intent的构造函数中指定

        Intent intent = new Intent(this, ActFinishActivity.class);

        startActivity(intent);

    }

}

后台代码ActFinishActivity

package com.example.chapter04;

 

import androidx.appcompat.app.AppCompatActivity;

 

import android.os.Bundle;

import android.view.View;

 

public class ActFinishActivity extends AppCompatActivity implements View.OnClickListener {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_act_finish);

        findViewById(R.id.btn_finish).setOnClickListener(this);

        findViewById(R.id.iv_back).setOnClickListener(this);

    }

 

    @Override

    public void onClick(View v) {

        if (v.getId() == R.id.iv_back || v.getId() == R.id.btn_finish) {

            // 结束当前的活动页面

            finish();

        }

    }

}

运行:
https://note.youdao.com/yws/public/resource/27eebd0325090d0fc737b364d31e03b5/xmlnote/74755362BEE248C69CF7ABB5A086B36D/34130

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值