第六篇-以隱式意圖(Implicit Intent)呼叫系統服務
阿新 • • 發佈:2018-11-07
一、新建一個layout5.xml,同樣換為constriant模式。
二、拖動兩個Button到預覽介面,第一個按鈕名字改為DISPLAY WEBPAGE,第二個按鈕名字改為MAKE A CALL。第一個按鈕連線上左右。width改為match。第二個按鈕連線左右,上方連第一個按鈕的下方。width改為match,與第一個按鈕的距離改為16。切換到text模式,在第一個按鈕下新增android:onClick="openWebpage";第二個按鈕下新增android:onClick=makecall";alt+enter就在.java檔案下建了這兩個函式。
三、切換到main.java:
效果就是,點選DISPLAY WEBPAGE按鈕會跳到蘋果介面。
效果就是點選按鈕,會出現以下介面
layout5.xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button11" android:onClick="openWebpage" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:text="DISPLAY WEBPAGE" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/button12" android:onClick="makecall" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="16dp" android:layout_marginEnd="8dp" android:text="MAKE A CALL" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/button11" /> </android.support.constraint.ConstraintLayout>
main.xml:
package com.example.aimee.aimeetest1; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.layout); setContentView(R.layout.layout5); } public void JumpToScreen2(View view) { Intent i=new Intent(this,Layout4Activity.class); startActivity(i); } public void openWebpage(View view) { Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com")); startActivity(i); } public void makecall(View view) { Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse("tel:***********")); startActivity(i); } }