‘壹’ 开发android 怎样实现登录界面的跳转 详细
intent跳转有两种方式,一种是我们常用的显示跳转,还有一种是隐式跳转。
显式方式:Intent aIntent = new Intent(this,XXActivity.class);第一个是你当前Activity的对象,第一个参数是你要跳转Activity的类。这种方式适合在同一个APP中的内部跳转。
隐式方式:Intent aIntent = new Intent("actiionXXXXXXX"),参数为你在AndroidManifest.xml中配置的Actitiy中<intent-filter><action android:name="actionXXXXXXXX"/><intent-filter>
‘贰’ android怎么用intent跳转页面
Android页面跳转Intent使用
在android中,一个页面就是一个activity,在页面跳转中,用到了Intent这个类,其实Intent跳转没什么大不了的,就是调用几个方法,第一个:intent.setAction(“wang.zhe.gui.lai”);当然,里面的”wang.zhe.gui.lai”这个字符串是要在主配置文件中配置的,第二个:intent.setClass(MainActivity.this,SceondViewActivity.class);这个跳转方法是最常用的一种,这两种方法之后,用startActivity(intent);来启动跳转。不过这不是我说的重点,我所要说的是如何传值?一般对于字符串的传值,就是调用intent.putExtra("str",”字符串内容”);来传值,但是要是传一个对象呢?在intent中提供了一个方法,也是 putExtra(),不过,这个是传对象的方法putExtra(String name, Serializable value),是可以传对象的,不过对应的对象要序列化,其实就是实现一个标示接口Serializable,下面将部分源码附上。
这是一个userinfo类
package com.example.regist;
import java.io.Serializable;
public class Userinfo implements Serializable {
String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public String getUserGender() {
return userGender;
}
public void setUserGender(String userGender) {
this.userGender = userGender;
}
public String getUserBathday() {
return userBathday;
}
public void setUserBathday(String userBathday) {
this.userBathday = userBathday;
}
public String getUserLove() {
return userLove;
}
public void setUserLove(String userLove) {
this.userLove = userLove;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
String userPassword;
String userGender;
boolean userIsmarry;
public boolean isUserIsmarry() {
return userIsmarry;
}
public void setUserIsmarry(boolean userIsmarry) {
this.userIsmarry = userIsmarry;
}
String userBathday;
String userLove;
String userEmail;
}
可以看出该类实现了Serializable接口。
下面是跳转加传值的部分代码:
Intent intent=new Intent();
intent.setClass(MainActivity.this,SecondviewActivity.class);
intent.putExtra("user",user);//user是实例化之后的对象
startActivity(intent);
下面是第二个界面所对应的类接受传过来的对象的代码
TextView tex=new TextView(this);
Intent intent=getIntent();
Userinfo user=(Userinfo) intent.getSerializableExtra("user");
现在就是一个完整的user对象了,你可以随性而用了。
‘叁’ android 界面跳转怎么控制
下面关于界面跳转的例子来自于android学习手册,如果想看实际运行的例子的话,请去下载,并且可以看源码和文档。android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行, 源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳
android使用,从一个Activity(界面)跳转到另一个Activity时,需要使用到Intent来启动Activity。在Intent使用时,分为显式调用和隐式调用2类,显式调用就是直接调用另一个Activity的class类,隐式调用需要通过调用另一个Activity的action 来启动另一个Activity,详细如下:
Intent在android中的定义为:public Intent (Context packageContext , Class<?> cls);
1、显式调用---直接调用Activity的Class类
例,Activity1调用Activity2
Intent intent = new Intent(this , Activity2.class);
startActivity(intent);
2、隐式调用
Activity1隐式调用Activity2时需要在AndroidManifest.xml文件中配置Activity2的action和category,具体添加下面的代码到Activity2的定义中
<intent-filter>
<action android:name="myaction2"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="mycategory" />
</intent-filter>
接着同样使用intent来启动Activity,代码如下:
Intent intent = new Intent("myaction2");
startActivity(intent);
这样就可以启动Activity2
注:在使用intent隐式调用Activity时会遇到多个Activity的intent-filter中的action和category相同时,这时android会先弹出一个选择界面的窗口,显式要启动的Activity列表,根据用户的选择来启动Activity,如Activity2和Activity3的action和category相同
<Activity android:name=".Activity2">
<intent-filter>
<action android:name="myaction2"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="myCategory" />
</intent-filter>
</Activity>
<Activity android:name=".Activity3">
<intent-filter>
<action android:name="myaction2"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="myCategory" />
</intent-filter>
</Activity>
启动Activity代码如下:
Intent intent = new("action2");
intent.addCategory("myCategory");
startActivity(intent);
这时就会弹出Acvity的选择窗口,选择启动activity2还是activity3
‘肆’ android开发中,像浏览器导航页面那样点击怎么跳转到另一个Activity页面显示出来。怎样传值和接收……
你可以获取对话框的点击事件,比如点击了确定然后你就跳转
AlertDialog.Builder builder = new Builder(CommentActivity.this);
builder.setMessage("确定要跳转吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
arg0.dismiss();
这里跳转到你想要去的页面
}
});
builder.setNegativeButton("取消",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
arg0就是该listener的接口啊,通过这个参数就可以关闭对话框。
跳到想去的页面就startIntent就好了,你把那一行中文换成 Intent it = new Intent(this,UserActivity.class); startActivity(it); 当然要跳去哪个页面就你自己决定
AlertDialog.Builder builder = new Builder(CommentActivity.this);
builder.setMessage("确定要跳转吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
arg0.dismiss();
Intent it = new Intent(this,UserActivity.class);
startActivity(it);
}
});
builder.setNegativeButton("取消",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
还不错,希望你采纳。
‘伍’ 安卓中如何实现页面跳转
安卓实现页面跳转及传递参数教程:
用类名跳转
Intent负责对应用中一次操作的动作、动作涉及数据、附加数据进行描述,Android则根据此Intent的描述, 负责找到对应的组件,将 Intent传递给调用的组件,并完成组件的调用。Intent在这里起着实现调用者与被调用者之间的解耦作用。
Intent传递过程中,要找到目标消费者(另一个Activity,IntentReceiver或Service),也就是Intent的响应者。
Java代码packagecom.Android;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.formstuff);
finalImageButtonbutton=(ImageButton)findViewById(R.id.android_button);
button.setOnClickListener(newOnClickListener(){
publicvoidonClick(Viewv){
//用类名跳转,需要在AndroidManifest.xml中申明activity
Intentintent=newIntent(FormStuff.this,HelloTabWidget.class);
startActivity(intent);
}
});
}
复制代码Xml代码<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.Android"android:versionCode="1"android:versionName="1.0">
<applicationandroid:icon="@drawable/icon"android:theme="@android:style/Theme.NoTitleBar">
<activityandroid:name=".FormStuff"android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--申明activity-->
<activityandroid:name="HelloTabWidget"></activity>
</application>
<uses-sdkandroid: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(http://www.google.com);
Intent i = new Intent(Intent.ACTION_VIEW,uri);手机的Intent分发过程中,会根据http://www.google.com 的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代码packagecom.android.edit_text;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.KeyEvent;
importandroid.view.View;
importandroid.widget.EditText;
{
privateTextViewm_TextView;
privateEditTextm_EditText;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_EditText=(EditText)this.findViewById(R.id.EditText01);
m_EditText.setOnKeyListener(editTextKeyListener);
}
privateEditText.=newEditText.OnKeyListener(){
@Override
publicbooleanonKey(Viewarg0,intarg1,KeyEventarg2){
//action跳转,需要在AndroidManifest.xml中配置action
Intenti=newIntent("android.intent.action.mydialog");
MyEditText.this.startActivity(i);
returnfalse;
}
};
}
复制代码Xml代码<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.edit_text"android:versionCode="1"
android:versionName="1.0">
<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
<activityandroid:name=".MyEditText"android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--配置跳转activity-->
<activityandroid:name="com.android.dialog.MyDialog">
<intent-filter>
<!--配置action路径-->
<actionandroid:name="android.intent.action.mydialog"/>
<categoryandroid:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
<uses-sdkandroid:minSdkVersion="7"/>
</manifest>
‘陆’ Android跳转页面用Intent隐式好还是显示好
各有各的好处……显式的可以从1个Activity跳到另外一个明确的Activity。隐式的就不确定跳到哪个Activity了,但是要对跳转进行描述,描述的内容就是目标Activity的特点,那么系统会自动匹配你需要的目标Activity了。
例如Intent intent = new Intent(Intent.ACTION_CALL); 就是为intent 绑定了ACTION_CALL的动作,就是打电话。
‘柒’ 请问Android大神们,如何实现多个按钮跳转到一个页面,但根据不同的按钮显示不同内容
每个按钮的处理,在标记里传不同的值,如下
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("mark", 0);
然后在你跳转后的activity里,调用以下方法即可取到你设置的值
int mark = getIntent().getIntExtra("mark", -1);
根据你不同按钮跳转设置不同的mark值,然后在新开的页面上,获取到mark值,就可以判断是哪个按钮跳转过来的,然后就可以继续你需要的逻辑了
‘捌’ Android怎么跳转到第三方应用的指定界面
界面的转跳都是由Intent来实现的这个Intent,有两种方式,一种叫显示意图,一种叫隐式意图你调用其它APK的界面,那只能通过隐式意图去激活了比如说,你要调用系统的相机拍照,或者调用文件管理器选择文件,这些都是通过隐式意图来实现的
‘玖’ 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、最后,就可以就可以跳转到下一个页面了。