日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

安卓 激活应用组件 intent

發(fā)布時間:2025/5/22 编程问答 65 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓 激活应用组件 intent 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在執(zhí)行應用程序中需要調(diào)用另一個活動,也就是實現(xiàn)頁面跳轉

1. 顯式intent 跳轉頁面

1.1 帶參 一個或多個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="${relativePackage}.${activityClass}" ><EditTextandroid:id="@+id/editText1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/textView1"android:layout_marginLeft="44dp"android:layout_marginTop="32dp"android:ems="10"android:text="輸入用戶名"><requestFocus /></EditText><EditTextandroid:id="@+id/editText2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/editText1"android:layout_centerHorizontal="true"android:layout_marginTop="61dp"android:ems="10"android:text="密碼"/><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/editText2"android:layout_centerVertical="true"android:layout_marginLeft="22dp"android:text="Button" /></RelativeLayout>

主活動

TextView textView1;@Override protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.one);textView1 = (TextView) findViewById(R.id.textView1);// 接收數(shù)據(jù)Intent intent = getIntent();// 方法一String username = intent.getStringExtra("username");// 方法2//Bundle bundle = intent.getExtras();//String username = bundle.getString("username");textView1.setText(username);textView1.setTextColor(Color.RED);textView1.setTextSize(20);}

第二個頁面

TextView textView1;@Override protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.one);textView1 = (TextView) findViewById(R.id.textView1);// 接收數(shù)據(jù)Intent intent = getIntent();// 方法一String username = intent.getStringExtra("username");// 方法2//Bundle bundle = intent.getExtras();//String username = bundle.getString("username");textView1.setText(username);textView1.setTextColor(Color.RED);textView1.setTextSize(20);}

1.2 無參數(shù) 跳轉頁面

// 添加點擊事件 btn1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent(MainActivity.this, Two.class);// 啟動另外一個活動startActivity(intent);} });

2 注冊活動 AndroidManifest.xml

<!-- 注冊活動 --> <activityandroid:name=".Two"><intent-filter><action android:name="two" /><category android:name="android.intent.category.DEFAULT" /></intent-filter> </activity>

3 案例:隱式 intent撥打電話

常量目標組件操作
ACTION_CALL活動撥通電話的界面
ACTION_EDIT活動填號碼的界面
ACTION_MAIN活動
ACTION_BATTERY_LOW
ACTION_HEADSERT_LPLUG

MainActivity.java

public class MainActivity extends Activity {EditText editText1;Button btn1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);editText1 = (EditText) findViewById(R.id.editText1);btn1 = (Button) findViewById(R.id.button1);btn1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubString num = editText1.getText().toString();Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+ num));startActivity(intent);}}); }

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="${relativePackage}.${activityClass}" ><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="輸入手機號" /><EditTextandroid:id="@+id/editText1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button1"android:layout_below="@+id/textView1"android:layout_marginTop="24dp"android:ems="10" /><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/editText1"android:layout_marginLeft="26dp"android:layout_marginTop="118dp"android:text="撥打" /></RelativeLayout>

權限添加 AndroidMainifest.xml

<uses-permission android:name="android.permission.CALL_PHONE"/>

總結

以上是生活随笔為你收集整理的安卓 激活应用组件 intent的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。