手機撥號器

2022-03-28 02:17:20 字數 2490 閱讀 5677

1

布局管理器中的**:23

4""5 xmlns:tools="

"6 android:layout_width="

match_parent

"7 android:layout_height="

match_parent

"8 android:paddingbottom="

@dimen/activity_vertical_margin

"9 android:paddingleft="

@dimen/activity_horizontal_margin

"10 android:paddingright="

@dimen/activity_horizontal_margin

"11 android:paddingtop="

@dimen/activity_vertical_margin

"12 tools:context="

.mainactivity

" >

1314

15 android:id="

@+id/textview3

"16 android:layout_width="

wrap_content

"17 android:layout_height="

wrap_content

"18 android:layout_margintop="

20dp

"19 android:text="

請輸入**號碼

" />

2021

22 android:id="

@+id/et_number

"23 android:layout_width="

wrap_content

"24 android:layout_height="

wrap_content

"25 android:layout_alignleft="

@+id/textview3

"26 android:layout_below="

@+id/textview3

"27 android:layout_margintop="

18dp

"28 android:ems="

10" >

2930

3132

3334 android:id="

@+id/btn_call

"35 android:layout_width="

wrap_content

"36 android:layout_height="

wrap_content

"37 android:layout_alignleft="

@+id/et_number

"38 android:layout_below="

@+id/et_number

"39 android:layout_margintop="

22dp

"40 android:text="

撥打此號碼

" />

4142

4344

45mainactivity中**:

4647

public

class

mainactivity extends activity

66//

建立乙個方法實現onclicklistener介面 定義按鈕監聽

67private

class

mybuttononclick implements android.view.view.onclicklistener

82//

(5).開始撥打** intent呼叫手機號碼

83 intent intent = new intent();//

建立乙個意圖的物件

84//

(6).設定撥打**的動作

85intent.setaction(intent.action_call);

8687

//(7).設定撥打**的資料 (tel:) 是固定寫法,不能寫成大寫

88 intent.setdata(uri.parse("

tel:

"+number));//

uri 同意資源識別符號

89//

(8).開啟意圖;

90startactivity(intent);

9192}93

9495}96

97 }

效果圖

電話撥號器

1.直接撥號 新增許可權 android name android.permission.call phone public class mainactivity extends activity 如果乙個引數是乙個介面 1.定義乙個類去實現這個介面 private class myclicklis...

電話撥號器

執行結果 1.新增許可權 uses permission android name android.permission.call phone 2.實現 1.先獲取輸入的 號碼 並去掉前後空格 string number et.gettext tostring trim 2.對號碼做非空判斷 如果號...

Android電話撥號器

1 主要分為兩部分,布局和邏輯 首先看布局如下 2 下面是邏輯 package cn.zxy.phone import android.net.uri import android.os.bundle import android.view.view import android.view.view...