琼海扯僖物流有限公司

【全國】 集團(tuán)簡(jiǎn)介 關(guān)注我們
幫學(xué)院 商標(biāo)分類表-2024尼斯分類 知識(shí)產(chǎn)權(quán)交易

快幫集團(tuán)

android頁面跳轉(zhuǎn)和切換的方式

2019-03-23

第一種方式,用action來跳轉(zhuǎn)。

 

1、使用Action跳轉(zhuǎn),如果有一個(gè)程序的 AndroidManifest.xml中的某一個(gè)ActivityIntentFilter段中定義了包含了相同的Action那么這個(gè)Intent 就與這個(gè)目標(biāo)Action匹配。如果這個(gè)IntentFilter段中沒有定義 Type,Category,那么這個(gè) Activity就匹配了。但是如果手機(jī)中有兩個(gè)以上的程序匹配,那么就會(huì)彈出一個(gè)對(duì)話可框來提示說明。


Action的值在Android中有很多預(yù)定義,如果你想直接轉(zhuǎn)到你自己定義的Intent接收者,你可以在接收者的 IntentFilter中加入一個(gè)自定義的Action值(同時(shí)要設(shè)定 Category值為"android.intent.category.DEFAULT"),在你的Intent中設(shè)定該值為Intent Action,就直接能跳轉(zhuǎn)到你自己的Intent接收者中。因?yàn)檫@個(gè)Action在系統(tǒng)中是唯一的。

 

2,data/type,你可以用Uri來做為data,比如Uri uri = Uri.parse(http://www.google.com);


Intent i = new Intent(Intent.ACTION_VIEW,uri);手機(jī)的Intent分發(fā)過程中,會(huì)根據(jù)http://www.google.com scheme判斷出數(shù)據(jù)類型type


手機(jī)的Brower則能匹配它,在BrowerManifest.xml中的IntenFilter中首先有ACTION_VIEW Action,也能處理http:type。

 

3,至于分類Category,一般不要去在Intent中設(shè)置它,如果你寫Intent的接收者,就在Manifest.xml Activity IntentFilter中包含android.category.DEFAULT,這樣所有不設(shè)置 CategoryIntent.addCategory(String c);)的Intent都會(huì)與這個(gè)Category匹配。

 

4,extras(附加信息),是其它所有附加信息的集合。使用extras可以為組件提供擴(kuò)展信息,比如,如果要執(zhí)行發(fā)送電子郵件這個(gè)動(dòng)作,可以將電子郵件的標(biāo)題、正文等保存在extras里,傳給電子郵件發(fā)送組件。

 

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跳轉(zhuǎn),需要在AndroidManifest.xml中配置action

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

         MyEditText.this.startActivity(i);

        

         return false;

       }

};

}

復(fù)制代碼Xml代碼 <?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/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>

            <!--配置跳轉(zhuǎn)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>

復(fù)制代碼第二種方式,用類名跳轉(zhuǎn)。

 

Intent負(fù)責(zé)對(duì)應(yīng)用中一次操作的動(dòng)作、動(dòng)作涉及數(shù)據(jù)、附加數(shù)據(jù)進(jìn)行描述,Android則根據(jù)此Intent的描述, 負(fù)責(zé)找到對(duì)應(yīng)的組件,將 Intent傳遞給調(diào)用的組件,并完成組件的調(diào)用。Intent在這里起著實(shí)現(xiàn)調(diào)用者與被調(diào)用者之間的解耦作用。

Intent傳遞過程中,要找到目標(biāo)消費(fèi)者(另一個(gè)Activity,IntentReceiverService),也就是Intent的響應(yīng)者。

 

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

// 用類名跳轉(zhuǎn),需要在AndroidManifest.xml中申明activity

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

            startActivity(intent);

         }

       });

 

}

復(fù)制代碼Xml代碼 <?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/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">

文章內(nèi)容來源于網(wǎng)絡(luò),侵刪

常見問題

京公網(wǎng)安備 11010802036823號(hào)

   

京ICP備16051929號(hào)

   

增值電信業(yè)務(wù)許可證編號(hào):京B2-20190686

   

專利代理機(jī)構(gòu)代碼:16087

   

人力資源服務(wù)許可證編號(hào):1101082019043

   

代理記賬許可證書編號(hào):DLJZ11010820210015

0
芷江| 西城区| 广水市| 大安市| 长乐市| 西华县| 高密市| 库尔勒市| 加查县| 怀集县| 青冈县| 清新县| 高密市| 桦川县| 阿克陶县| 景洪市| 郧西县| 白水县| 寻乌县| 杂多县| 张家口市| 铜梁县| 永安市| 婺源县| 云南省| 锡林郭勒盟| 措美县| 长顺县| 康定县| 策勒县| 鹤庆县| 武汉市| 兴隆县| 林口县| 镇沅| 乐都县| 惠来县| 高台县| 绥化市| 望城县| 昌吉市|