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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: xcap工具使用心得
- 下一篇: jQuery实现登录提示