快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

android跳转页面,android跳转页面代码

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;

TIPS:在类上会添加:import android.widget.Button;

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);

}

});

TIPS:在类上会添加:import android.content.Intent;

4、最后,就可以就可以跳转到下一个页面了。

Android模块化页面跳转Scheme

Android模块化页面跳转Scheme

Github

通过注解实现Uri页面跳转

支持参数自动解析

使用场景:

1、应用内服务端下发uri进行页面跳转

2、通知栏点击,携带uri进行页面跳转

3、其他应用通过uri调起进行页面跳转

注:activity的注解格式:group/path

group为各个模块的唯一字符串,不同模块不可重复

接入:

使用姿势:

根build.gradle

module依赖:

使用姿势:

场景1:应用内服务端下发uri进行页面跳转

1、在需要支持uri跳转的Activity增加注解@SchemePath("{随意填,唯一字符串}")

2、跳转事件

注:参数支持

uri支持参数,如" scheme://ModuleA/Activity?data=1time=20200714hasData=true "

Activity的参数增加@SchemeExtra注解,如

场景2:通知栏点击,携带uri进行页面跳转

1、应用首页Activity增加注解@SchemePath("{随意填}")

2、application调用初始化

3、启动页,通知栏点击入口

场景三:其他应用通过uri调起进行页面跳转

1、注册中转activity

Android页面跳转协议_URL Scheme详解

android中的scheme是一种页面内跳转协议,是一种非常好的实现机制,通过定义自己的scheme协议,可以非常方便跳转app中的各个页面;通过scheme协议,服务器可以定制化告诉App跳转那个页面,可以通过通知栏消息定制化跳转页面,可以通过H5页面跳转页面等。

客户端应用可以在服务端注册一个URL Scheme,该Scheme用于从浏览器或其他应用启动本应用。通过指定的URL字段,可以让应用在被调起后直接打开某些特定界面,比如商品详情页,活动详情页等。也可以执行某些特定的动作,如完成支付等。也可以在应用内通过html页来直接调用显示app内的某个界面。综上URL Schema使用场景大致分以下几种:

一个完整的Scheme的协议格式由 scheme、userInfo、host、port、path、query和fragment 组成。结构如下:

scheme://是固定的格式。userInfo@ 可以省略,host 是必须的。port 、query 和 fragment 也是可以省略的。

其中scheme既可以是Android已经定义好的协议,也可使用我们自定义的。Android 常见的scheme 协议有:content 、file、http 等。如果我们自定义协议就可以随意使用一些字符串来限定协议。当然最好是有一定含义的字符串。如下面的协议:

首先配置需要跳转的Activity,Mainifest文件配置如下:

SchemeActivity

在网页中调用:

运行结果如下:

其他运用方式都基于样例,源码地址: URL_SchemeDemo

安卓中如何实现页面跳转

安卓实现页面跳转及传递参数教程:

用类名跳转

Intent负责对应用中一次操作的动作、动作涉及数据、附加数据进行描述,Android则根据此Intent的描述, 负责找到对应的组件,将 Intent传递给调用的组件,并完成组件的调用。Intent在这里起着实现调用者与被调用者之间的解耦作用。

Intent传递过程中,要找到目标消费者(另一个Activity,IntentReceiver或Service),也就是Intent的响应者。

Java代码 package com.Android; 

import android.app.Activity; 

import android.content.Intent; 

import android.os.Bundle; 

import android.view.View; 

import android.view.View.OnClickListener; 

public class FormStuff extends Activity { 

@Override 

public void onCreate(Bundle savedInstanceState) { 

super.onCreate(savedInstanceState); 

setContentView(R.layout.formstuff); 

final ImageButton button = (ImageButton) findViewById(R.id.android_button); 

button.setOnClickListener(new OnClickListener() { 

public void onClick(View v) { 

// 用类名跳转,需要在AndroidManifest.xml中申明activity 

Intent intent = new Intent(FormStuff.this, HelloTabWidget.class); 

startActivity(intent); 

}); 

复制代码Xml代码 ?xml version="1.0" encoding="utf-8"? 

manifest xmlns:android="" 

package="com.Android" android:versionCode="1" android:versionName="1.0" 

application android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar" 

activity android:name=".FormStuff" android:label="@string/app_name" 

intent-filter 

action android:name="android.intent.action.MAIN" / 

category android:name="android.intent.category.LAUNCHER" / 

/intent-filter 

/activity 

!--申明activity-- 

activity android:name="HelloTabWidget"/activity 

/application 

uses-sdk android:minSdkVersion="4" / 

/manifest

使用Action跳转实现

使用Action跳转,如果有一个程序的 AndroidManifest.xml中的某一个Activity的IntentFilter段中定义了包含了相同的Action那么这个Intent 就与这个目标Action匹配。如果这个IntentFilter段中没有定义 Type,Category,那么这个 Activity就匹配了。但是如果手机中有两个以上的程序匹配,那么就会弹出一个对话可框来提示说明。

Action的值在Android中有很多预定义,如果想直接转到你自己定义的Intent接收者,可以在接收者的 IntentFilter中加入一个自定义的Action值(同时要设定 Category值为"android.intent.category.DEFAULT"),在Intent中设定该值为Intent的 Action,就直接能跳转到自己的Intent接收者中。因为这个Action在系统中是唯一的。

data/type,可以用Uri来做为data,比如Uri uri = Uri.parse();

Intent i = new Intent(Intent.ACTION_VIEW,uri);手机的Intent分发过程中,会根据 的scheme判断出数据类型type

手机的Brower则能匹配它,在Brower的Manifest.xml中的IntenFilter中首先有ACTION_VIEW Action,也能处理http:的type。

至于分类Category,一般不要去在Intent中设置它,如果写Intent的接收者,就在Manifest.xml的 Activity的 IntentFilter中包含android.category.DEFAULT,这样所有不设置 Category(Intent.addCategory(String c);)的Intent都会与这个Category匹配。

extras(附加信息),是其它所有附加信息的集合。使用extras可以为组件提供扩展信息,比如,如果要执行“发送电子邮件”这个动作,可以将电子邮件的标题、正文等保存在extras里,传给电子邮件发送组件。

Java代码 package com.android.edit_text; 

import android.app.Activity; 

import android.content.Intent; 

import android.os.Bundle; 

import android.view.KeyEvent; 

import android.view.View; 

import android.widget.EditText; 

public class MyEditText extends Activity { 

private TextView m_TextView; 

private EditText m_EditText; 

@Override 

public void onCreate(Bundle savedInstanceState) { 

super.onCreate(savedInstanceState); 

setContentView(R.layout.main); 

m_EditText = (EditText) this.findViewById(R.id.EditText01); 

m_EditText.setOnKeyListener(editTextKeyListener); 

private EditText.OnKeyListener editTextKeyListener = new EditText.OnKeyListener() { 

@Override 

public boolean onKey(View arg0, int arg1, KeyEvent arg2) { 

// action跳转,需要在AndroidManifest.xml中配置action 

Intent i = new Intent("android.intent.action.mydialog"); 

MyEditText.this.startActivity(i); 

return false; 

}; 

复制代码Xml代码 ?xml version="1.0" encoding="utf-8"? 

manifest xmlns:android="" 

package="com.android.edit_text" android:versionCode="1" 

android:versionName="1.0" 

application android:icon="@drawable/icon" android:label="@string/app_name" 

activity android:name=".MyEditText" android:label="@string/app_name" 

intent-filter 

action android:name="android.intent.action.MAIN" / 

category android:name="android.intent.category.LAUNCHER" / 

/intent-filter 

/activity 

!--配置跳转activity-- 

activity android:name="com.android.dialog.MyDialog" 

intent-filter 

!--配置action路径-- 

action android:name="android.intent.action.mydialog" / 

category android:name="android.intent.category.DEFAULT" / 

/intent-filter 

/activity 

/application 

uses-sdk android:minSdkVersion="7" /

/manifest

android:点击按钮后跳转另一页面

01

进入墨刀界面,将需要进行交互动作的界面扔进墨刀中打开。

02

在左侧左键选择“链接区域”,然后拖动到界面中需要进行交互设计的按钮位置。

03

位置确定之后,左键点击区域旁边的小按钮,拖动到目标界面中。

04

进入预览模式,点击刚才设置的区域就能够进行跳转了。

android页面跳转的几种方式

android页面跳转的话,现在更多是流行使用fragment来进行切换,还有就是intent来进行跳转。


名称栏目:android跳转页面,android跳转页面代码
分享路径:http://6mz.cn/article/dsdhcco.html

其他资讯