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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

android之隐示意图跳转启动另一个activity

發布時間:2023/12/9 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android之隐示意图跳转启动另一个activity 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

主面板布局:layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"?
? ? android:orientation="vertical">


? ? <Button
? ? ? ? android:id="@+id/btnStartSecondActivity"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="start SecondActivity" />
? ? <Button
? ? ? ? android:id="@+id/btnBrowser"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="瀏覽網頁" />
? ? <Button
? ? ? ? android:id="@+id/btnCall"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="撥打電話" />
? ? <Button
? ? ? ? android:id="@+id/btnDial"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="啟動撥號面板" />
? ? <Button
? ? ? ? android:id="@+id/btnUninstall"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="卸載應用程序" />
? ? <Button
? ? ? ? android:id="@+id/btnInstall"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="安裝應用程序" />
? ? <Button
? ? ? ? android:id="@+id/btnSendSms"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="發送短信" />
? ? <Button
? ? ? ? android:id="@+id/btnPlayMusic"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="播放音樂" />
? ??

</LinearLayout>

主面板調用java代碼:

package com.sxt.day04_06;


import java.io.File;


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;


public class MainActivity extends Activity implements OnClickListener {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListener();
}


private void setListener() {
findViewById(R.id.btnBrowser).setOnClickListener(this);
findViewById(R.id.btnCall).setOnClickListener(this);
findViewById(R.id.btnDial).setOnClickListener(this);
findViewById(R.id.btnInstall).setOnClickListener(this);
findViewById(R.id.btnPlayMusic).setOnClickListener(this);
findViewById(R.id.btnSendSms).setOnClickListener(this);
findViewById(R.id.btnStartSecondActivity).setOnClickListener(this);
findViewById(R.id.btnUninstall).setOnClickListener(this);
}


@Override
public void onClick(View v) {
Intent intent = null;
switch (v.getId()) {
case R.id.btnBrowser:
//瀏覽網頁
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
break;
case R.id.btnCall:
//打電話
intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:15555215554"));
break;
case R.id.btnDial:
//啟動撥號面板
intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:68337799"));
break;
case R.id.btnInstall: {
//找到sdk中的安裝文件,然后進行安裝
// 找到sd卡的Download目錄

File dir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(dir, "baidu_safe.apk");
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
}
break;
case R.id.btnPlayMusic:
//播放音樂文件
intent = new Intent(Intent.ACTION_VIEW);
File dir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(dir, "yielaixiang.mp3");
intent.setDataAndType(Uri.fromFile(file), "audio/mp3");
break;
case R.id.btnSendSms:
//發送短信
intent=new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:13377558899"));
intent.putExtra("sms_body", "hello android!");
break;
case R.id.btnStartSecondActivity://隱示意圖跳轉到另一個activity
intent=new Intent("com.sxt.day04_06.SecondActivity");
break;
case R.id.btnUninstall://卸載安裝好的文件
intent=new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.sxt.day04_01"));
break;
}
startActivity(intent);
}


}

次面板布局:layout/activity_second.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"
? ? android:paddingBottom="@dimen/activity_vertical_margin"
? ? android:paddingLeft="@dimen/activity_horizontal_margin"
? ? android:paddingRight="@dimen/activity_horizontal_margin"
? ? android:paddingTop="@dimen/activity_vertical_margin"
? ? tools:context=".SecondActivity" >


? ? <TextView
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="@string/hello_world" />


</RelativeLayout>

次面板java代碼:

package com.sxt.day04_06;


import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;


public class SecondActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Log.i("main","SecondActivity.onCreate()");
}


}

清單xml:AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
? ? package="com.sxt.day04_06"
? ? android:versionCode="1"
? ? android:versionName="1.0" >


? ? <uses-sdk
? ? ? ? android:minSdkVersion="8"
? ? ? ? android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CALL_PHONE"/> (這兩個是權限的)
<uses-permission android:name="android.permission.INTERNET"/>

? ? <application
? ? ? ? android:allowBackup="true"
? ? ? ? android:icon="@drawable/ic_launcher"
? ? ? ? android:label="@string/app_name"
? ? ? ? android:theme="@style/AppTheme" >
? ? ? ? <activity
? ? ? ? ? ? android:name="com.sxt.day04_06.MainActivity"
? ? ? ? ? ? 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
? ? ? ? ? ? android:name="com.sxt.day04_06.SecondActivity"
? ? ? ? ? ? android:label="@string/title_activity_second" >
? ? ? ? ? ? <intent-filter>
? ? ? ? ? ? ? ? <action android:name="com.sxt.day04_06.SecondActivity"/>
? ? ? ? ? ? ? ? <category android:name="android.intent.category.DEFAULT"/>
? ? ? ? ? ? </intent-filter>
? ? ? ? </activity>
? ? </application>


</manifest>

效果:





轉載于:https://www.cnblogs.com/qa962839575/p/4148592.html

總結

以上是生活随笔為你收集整理的android之隐示意图跳转启动另一个activity的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。