撥號界面:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- match_parent: 匹配父元素,父元素有多寬,我就有多寬;父元素有多高,我就有多高 -->
<!-- wrap_content:包裹內容,我的內容有多高,我就有多高,我的內容有多寬,我就有多寬 -->
<EditText
android:id="@+id/et_input_num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" >
</EditText>
<!-- android:text: 指定按鈕上的顯示文字 -->
<!-- android:onClick: 定義點擊事件 -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="call"
android:text="打電話" />
</LinearLayout>
// v: 代表你點擊的控件
public void call(View view) {
EditText editText = (EditText) findViewById(R.id.input_num);
// 獲取用戶輸入的手機號
String phone_number = editText.getText().toString();
//刪除字符串首部和尾部的空格
phone_number = phone_number.trim();
/**
* context : 上下文,環境 <br/>
* text : 要顯示的內容 <br/>
* duration : 顯示的時常 //持續時間
*
*/
Toast.makeText(this, phone_number, Toast.LENGTH_LONG);
if(phone_number != null && !phone_number.equals("")) {
//調用系統的撥號服務實現電話撥打功能
// 打電話
// Intent : 意圖.我想去做一件事
Intent t = new Intent();
// Action:動作.我具體想做什么事
// Intent.ACTION_DIAL: 激活撥號界面
// Intent.ACTION_CALL: 直接撥打電話
t.setAction(Intent.ACTION_CALL);
// Data: 數據.具體的動作所需要的附加數據
//封裝一個撥打電話的intent,並且將電話號碼包裝成一個Uri對象傳入
t.setData(Uri.parse("tel:" + phone_number));
// 通知系統你去幫我干活吧
startActivity(t);}
}
最后在在AndroidManifest.xml里面添加
<uses-permission android:name="android.permission.CALL_PHONE"/>
備注:
Toast.
makeText()使用方
法

1.默認的顯示方式

2.自定義顯示位置

3.帶圖片的

4.完全自定義顯示方式
