Android---页面跳转

Posted CircleSmart的个人博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android---页面跳转相关的知识,希望对你有一定的参考价值。

1、首先在一个布局文件(.XML)中绘画了一个跳转按钮(id为btn1):

<Button 
        android:id="@+id/btn1
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="跳转" />

2、然后在关联的类中声明一个私有button名称,如:

private Button btn1;

3、接着在类中onCreate的方法内执行以下操作:

    (1)、给btn1赋值,即设置布局文件中的Button按钮id进行关联,如:

btn1 = (Button) findViewById(R.id.btn1);

   

    (2)、给btn1绑定点击事件:

btn1.setOnClickListener(new View.OnClickListener(){ 
    @Override 
    public void onClick(View v){ 
    } 
});

TIPS:在类上会添加:import android.view.View;

    

     (3)、 给bnt1添加点击响应事件:

btn1.setOnClickListener(new View.OnClickListener(){ 
      @Override 
      public void onClick(View v){

          //Intent是一种运行时绑定(run-time binding)机制,它能在程序运行过程中连接两个不同的组件。

          //page1为先前已添加的类,并已在AndroidManifest.xml内添加活动事件(<activity android:name="page1"></activity>),在存放资源代码的文件夹下下, 
          Intent i = new Intent(MainActivity.this , page1.class);

          ////启动 
          startActivity(i); 
      } 
});

  















以上是关于Android---页面跳转的主要内容,如果未能解决你的问题,请参考以下文章

Android跳转到QQ加群、聊天页面

Android页面跳转协议_URL Scheme详解

Android开发,点击按钮跳转页面时,能跳转,但不显示布局,只有空白

Android 页面跳转模式

android Intent跳转页面之后按手机返回键 怎样使他不再返回到跳转之前的页面

Android中实现activity的页面跳转并传值