1.首先新建一个Android工程,命名为MyApp(名字可以自己随意起);

2.以原有的MainActivity.java文件为登录界面,然后在src文件中的包上面右击选择New目录下的Other中的Android Activity,选择BlankActivity,修改一个Activity的名字(自定义),我这里命名为BankActivity,点选finish然后新建完成一个返回页面;\

3.接下来就要添加布局文件了,我们在res文件下的layout文件里先双击activity_main.xml,在Android页面上拖入一个按钮,双击它,把android:id="@+id/btn1" 中的 "@+id/"后面的名字更改为btn1,然后android:text双引号中的文本改为登录,同样如此,将activity_bank.xml文件中的名字按照上述方法修改;

4.点开MainActivity.java文件,写入以下代码,记住是在OnCreate方法中编写代码哦!

 package com.example.myapp;

 import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //view层的控件和业务层的控件,靠id关联和映射 给btn1赋值,即设置布局文件中的Button按钮id进行关联
Button btn1=(Button)findViewById(R.id.btn1); //给btn1绑定监听事件
btn1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) { // 给bnt1添加点击响应事件
Intent intent =new Intent(MainActivity.this,BankActivity.class);
//启动
startActivity(intent);
}
}); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
} }

记得要在类上会添加:import android.content.Intent;

5.点开BankActivity.java文件:实现页面关闭,写入以下代码:

 package com.example.myapp;

 import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class BankActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bank); Button btn2=(Button)findViewById(R.id.btn2);
btn2.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_bank, menu);
return true;
} }

然后保存右击MyApp执行文件,就可以实现点击按钮跳转页面了!

实现这个小功能不是很难,以后的学习生活中遇到困难不要紧张,不要害怕,要积极采取策略解决掉问题,排除故障,一定要有自信,在成功面前,一切困难都是纸老虎,遇到问题,多动脑,勤思考,多动手,总会解决问题的。

一切事在人为!  世上无难事,只怕有心人。   小伙伴们,我们一起加油!!!

使用Android点击按钮跳转页面的更多相关文章

  1. 如何绑定android点击事件--跳转到另一个页面并实现关闭功能?

    一.点击按钮跳转到另一个页面. eg:实现从一个页面点击跳转到另一个页面 1.首先在一个布局文件(.XML)中绘画了一个跳转按钮(id为btn1): <Button         androi ...

  2. mui中confirm在苹果出现bug,confirm点击确定跳转页面再返回后,页面被遮罩盖住无法使用

    项目中使用confirm mui.confirm('您还未抽奖,现在去抽奖吗?', function (res) { if (res.index === 1) { window.location.hr ...

  3. jeecg 弹出框 点击按钮回调父页面 返回值

    jeecg 弹出框 点击按钮回调父页面 返回值 <t:base type="jquery"></t:base> <t:base type=" ...

  4. Android点击按钮拨打电话

    代码改变世界 Android点击按钮拨打电话 public void callPhone(String str) { Intent intent=new Intent(); intent.setAct ...

  5. Android中使用Intent的Action和Data属性实现点击按钮跳转到拨打电话和发送短信

    场景 点击拨打电话按钮,跳转到拨打电话页面 点击发送短信按钮,跳转到发送短信页面 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程 ...

  6. 关于showModalDialog()对话框点击按钮弹出新页面的问题

    页面a.aspx上,单击按钮a,走脚本,弹出showModalDialog("b.aspx",....) 在b.aspx上有个服务器控件按钮b,单击按钮,更新数据后,会弹出一个新的 ...

  7. iOS中点击按钮跳转到外部浏览器和内部打开

    如图所示,需要实现点击一个按钮,跳转到指定网页: -(void)pushBtnCellClickDeleate{ NSLog(@"跳转"); //在APP内部打开指定网页 UIWe ...

  8. layui点击按钮自动刷新页面问题

    问题 <button class="layui-btn layui-btn-primary" onclick="findData()">查询< ...

  9. Android中点击按钮获取string.xml中内容并弹窗提示

    场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...

随机推荐

  1. iOS中集成ijkplayer视频直播框架

    ijkplayer 是一款做视频直播的框架, 基于ffmpeg, 支持 Android 和 iOS, 网上也有很多集成说明, 但是个人觉得还是不够详细, 在这里详细的讲一下在 iOS 中如何集成ijk ...

  2. 利用vs2013简单初探Python

    最近无聊,某天无意在vs2013上发现了Python...... Python介绍:可以自己搜索一下. 接下来,准备工具: Win7搭建开发环境.需要准备Python.PTVS2013. 1.http ...

  3. JAVA - ATM机程序

    ATM机程序 UnionPayTest.java package oo.day06.work; public class UnionPayTest { } interface UnionPay{ // ...

  4. TCP_NODELAY

    启用TCP_NODELAY的情况下: 客户端程序C连接到服务器程序S: C仅接受数据,S仅发送数据 S循环调用send发送长度很小的数据包比如:10字节; 在C上用任务管理器查看到C的上行流量大约是下 ...

  5. dubbo源码分析5-dubbo的扩展点机制

    dubbo源码分析1-reference bean创建 dubbo源码分析2-reference bean发起服务方法调用 dubbo源码分析3-service bean的创建与发布 dubbo源码分 ...

  6. SQL Server错误与事务处理

    T-SQL中出现的错误,依据和事务的关系,可以分为两种情况: 有的错误会导致发生错误位置之后的代码不再执行,如果错误位置在事务中,该事务也会自动回滚(即在错误位置之后的rollback语句不会执行,但 ...

  7. 关注微信 即可连上wifi 的设计思路

    这个功能之前是在知乎上有人在询问后台的实现逻辑,然后才知道的。其实对微信的各种关注,实在是不想沾惹。 但是这个功能很有意思,当我关注了你,那么就可以在你的店里上wifi 。如果取消则立刻不能上网。 这 ...

  8. Linux内核内存管理子系统分析【转】

    本文转载自:http://blog.csdn.net/coding__madman/article/details/51298718 版权声明:本文为博主原创文章,未经博主允许不得转载. 还是那张熟悉 ...

  9. atomic vs. nonatomic

    Declaring a property atomic makes compiler generate additional code that prevents concurrent access ...

  10. 怎么在php里面利用str_replace防注入

    <php    /**    * 安全过滤函数    *    * @param $string    * @return string    */    function safe_repla ...