今天学习了如何进行界面之间的跳转。

用Intent进行页面跳转:

    Intent是一个将要执行的动作的抽象的描述,由Intent来协助完成Android各个组件之间的通讯。下面是一些代码。

 1 <?xml version="1.0" encoding="utf-8"?> 2  3     xmlns:tools="http://schemas.android.com/tools" 4     android:layout_width="match_parent" 5     android:layout_height="match_parent" 6     android:paddingBottom="@dimen/activity_vertical_margin" 7     android:paddingLeft="@dimen/activity_horizontal_margin" 8     android:paddingRight="@dimen/activity_horizontal_margin" 9     android:paddingTop="@dimen/activity_vertical_margin"10     android:orientation="vertical"11     tools:context="com.example.hp.app2.MainActivity">12 13     <Button14         android:id="@+id/btn1"15         android:text="按钮1"16         android:layout_width="match_parent"17         android:layout_height="wrap_content" />18 19     <Button20         android:id="@+id/btn2"21         android:text="按钮2"22         android:layout_width="match_parent"23         android:layout_height="wrap_content" />24 25 26 
package com.example.hp.app2;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;/** * Created by hp on 2020/2/11. */public class FirstActivity extends ActionBarActivity {    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_first);    }}
<?xml version="1.0" encoding="utf-8"?>    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView        android:textSize="25dp"        android:textColor="@android:color/holo_red_light"        android:text="这是第一个界面"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />

 

 1 package com.example.hp.app2; 2  3 import android.content.Intent; 4 import android.os.Bundle; 5 import android.support.v7.app.ActionBarActivity; 6 import android.view.View; 7  8 public class MainActivity extends ActionBarActivity implements View.OnClickListener { 9 10     @Override11     protected void onCreate(Bundle savedInstanceState) {12         super.onCreate(savedInstanceState);13         setContentView(R.layout.activity_main);14         initUI();15     }16 17     private void initUI() {18         findViewById(R.id.btn1).setOnClickListener( this);19         findViewById(R.id.btn2).setOnClickListener( this);20     }21 22 23     @Override24     public void onClick(View view) {25         switch (view.getId()){26             case R.id.btn1:27                 //跳转到第一个界面28                 //跳转界面用到了intent的方法29                 Intent intent = new Intent();30                 intent.setClass(getApplicationContext(),FirstActivity.class);31                 break;32             case R.id.btn2:33                 //第二个界面34                 break;35 36         }37     }38 }

 

更多相关文章

  1. UI布局之selector layer-list
  2. Android(安卓)自定义view仿微信相机单击拍照长按录视频按钮
  3. 【Android(安卓)界面效果49】RecyclerView高度随Item自适应
  4. Android(安卓)菜单BoomMenu(悬浮按钮弹出菜单)
  5. 关于Android界面编程与视图(View)组件
  6. Eclipse集成Android(安卓)NDK开发环境
  7. Android自定义Dialog弹框效果
  8. Android(安卓)ListView pull up to refresh 改造
  9. Android——四大组件、六大布局、五大存储

随机推荐

  1. Android核心分析 --分析方法论探讨之设计
  2. 物联网江湖 第二回- 列王的纷争 谷歌的利
  3. 最新android studio注意事项打不开等问题
  4. android.webkit.WebView 体验1: 使用html
  5. VisionMobile:移动平台生态系统冲突报告(
  6. Android(安卓)Fragment完全解析,关于碎片
  7. 第24章、OnLongClickListener长按事件(从
  8. Android软键盘弹起遮挡h5页面解决方法
  9. [转] android 中 任务、进程和线程的区别
  10. 最新消息:Android 4.0新增功能