AndroidStudio中使用Java实现1个按钮控制2个活动的功能
创始人
2024-08-21 05:00:21
0
  1. 首先创建两个活动,分别为ActivityOne和ActivityTwo。

  2. 在ActivityOne中设计一个按钮,然后在onCreate方法中添加如下代码:

     Button button = findViewById(R.id.button);
     button.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
             startActivity(intent);
         }
     });
    
  3. 在ActivityTwo中添加如下代码,实现返回ActivityOne的功能:

     @Override
     public void onBackPressed() {
         Intent intent = new Intent(ActivityTwo.this, ActivityOne.class);
         startActivity(intent);
     }
    

通过实现这些代码,当用户在ActivityOne中点击按钮时,应用将转到ActivityTwo。当用户在ActivityTwo中按下返回按钮时,应用将返回到ActivityOne。

相关内容

热门资讯

透视辅助!aapoker真的假... 透视辅助!aapoker真的假的(透视)插件(本来是有挂);1、不需要AI权限,帮助你快速的进行aa...
透视透视!aapoker怎么开... 透视透视!aapoker怎么开辅助器(透视)免费透视脚本(果然真的有挂);1、任何aapoker怎么...
透视肯定!aapoker破解侠... 透视肯定!aapoker破解侠是真的吗(透视)透视软件(总是真的有挂);1、上手简单,内置详细流程视...
透视插件!aapoker透视方... 透视插件!aapoker透视方法(透视)透视脚本下载(原来真的有挂)1)aapoker透视方法辅助挂...
透视代打!aapoker万能辅... 透视代打!aapoker万能辅助器(透视)万能辅助器(切实存在有挂)1、玩家可以在aapoker万能...
透视挂透视!aapoker脚本... 透视挂透视!aapoker脚本怎么用(透视)辅助(原来真的是有挂);1、下载好aapoker脚本怎么...
透视辅助!aapoker怎么设... 透视辅助!aapoker怎么设置抽水(透视)透视方法(真是真的有挂)1、进入游戏-大厅左侧-新手福利...
透视实锤!aapoker辅助器... 透视实锤!aapoker辅助器怎么用(透视)插件下载(总是真的有挂)1、完成aapoker辅助器怎么...
透视规律!aa poker透视... 透视规律!aa poker透视软件(透视)透视脚本下载(本来是真的有挂)运aa poker透视软件辅...
透视透视!aapoker辅助插... 透视透视!aapoker辅助插件工具(透视)透视方法(原来真的有挂)1、aapoker辅助插件工具a...