溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

1.4 Android應(yīng)用之電話拔號(hào)器

發(fā)布時(shí)間:2020-06-30 20:22:00 來(lái)源:網(wǎng)絡(luò) 閱讀:349 作者:GaiJianwei_ 欄目:移動(dòng)開發(fā)

實(shí)驗(yàn)?zāi)康?nbsp;

1.掌握簡(jiǎn)單的組件(TextView,EditText,Button)使用

2.掌握點(diǎn)擊事件的使用

電話拔號(hào)器效果圖

1.4 Android應(yīng)用之電話拔號(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è)試

1.4 Android應(yīng)用之電話拔號(hào)器



向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI