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. UINavigationBar 总结

    一.某个 ViewController 出现隐藏 NavigationBar - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear ...

  2. maven说

    maven打包命令:mvn assembly:assembly 打包成jar包需要修改配置把unpack改成false文件在: C:\Users\Administrator\.m2\repositor ...

  3. CSS之cssText

    更改元素样式 <div style="width:100px;height:100px;text-align:center;line-height:100px;"> T ...

  4. Java 使用jaxp删除节点

    <?xml version="1.0" encoding="UTF-8" standalone="no"?> <perso ...

  5. 前端开发利器-Brackets IDE

    是什么? http://brackets.io/ A modern, open source text editor that understands web design. 现代, 开源的文本编辑器 ...

  6. LUA OOP编程实现方法

    lua原生不支持OOP特性 确实如此, 同时可以采用其它lua代码的方式实现OOP的特性. OOP四大特性 抽象 封装 继承 多态 http://www.cnblogs.com/xiaosongluf ...

  7. Struts2(一):怎么创建对应版本的struts.xml

    1.eclisep导航菜单:windows->preferences->Xml->Xml Catalog; 2.在Xml Catalog右侧,添加一个新的XML Catalog: 3 ...

  8. H5 新标签用法及解释

    HTML 5 是一个新的网络标准,目标在于取代现有的 HTML 4.01, XHTML 1.0 and DOM Level 2 HTML 标准.它希望能够减少浏览器对于需要插件的丰富性网络应用服务(p ...

  9. JQuery 层次选择器

    <!DOCTYPE HTML> <html> <head> <title> 使用jQuery层次选择器 </title> <scrip ...

  10. GAT2.0使用文档(单接口开发)

    3   开始写用例 3.1接口用例开发 1)         准备工作 l  第一步从github(https://github.com/GeneralAutomationTesting/GAT2.0 ...