记账本APP5

给返回图标进行点击事件,而后效果是点击返回图标时,可以返回到主界面

AddActivity.java

复制代码
 1 public class AddActivity extends AppCompatActivity {
 2     //返回按钮
 3     private ImageView mBack;
 4 
 5     @Override
 6     protected void onCreate(Bundle savedInstanceState) {
 7         super.onCreate(savedInstanceState);
 8         setContentView(R.layout.activity_add);
 9         //返回
10         mBack=findViewById(R.id.back);
11         mBack.setOnClickListener(new View.OnClickListener() {
12             @Override
13             public void onClick(View v) {
14                 Toast.makeText(AddActivity.this,"返回成功",Toast.LENGTH_SHORT).show();
15                 Intent intent=null;
16                 //返回主页
17                 intent=new Intent(AddActivity.this,MainActivity.class);
18                 startActivity(intent);
19             }
20         });
21 
22     }
23 
24 }
复制代码

 

posted @ 2021-02-27 21:23  一口獠牙  阅读(43)  评论(0编辑  收藏  举报