您好,登錄后才能下訂單哦!
實(shí)驗(yàn)?zāi)康?nbsp;
1.掌握簡(jiǎn)單的組件(TextView,EditText,Button)使用
2.掌握點(diǎn)擊事件的使用
電話拔號(hào)器效果圖
界面布局代碼:
<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" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/title"/> <EditText android:id="@+id/phoneNumber" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="phone" android:layout_below="@id/title"/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/callPhone" android:layout_below="@id/phoneNumber"/> </RelativeLayout>
Java代碼實(shí)現(xiàn)撥打電話:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button=(Button) findViewById(R.id.button); button.setOnClickListener(this); } @Override public void onClick(View v) { //1.獲取輸入的電話號(hào)碼 EditText et=(EditText) findViewById(R.id.phoneNumber); String number=et.getText().toString(); //2.創(chuàng)建打電話意圖 Intent intent=new Intent(); intent.setAction(intent.ACTION_CALL); intent.setData(Uri.parse("tel:"+number)); startActivity(intent); }
注意 在AndroidManifest.xml添加撥打電話的權(quán)限
<uses-permission android:name="android.permission.CALL_PHONE"/>
測(cè)試:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。