Android 開發最簡單的快速撥打器(含源碼)

來源:互聯網
上載者:User

學習了一個星期了,總算學會了TextView、EditView、Button等基本的控制項,還有一點點布局的知識,然後佳哥(我的師傅)就叫我寫一個打電話的東西,感覺很神奇,不過經過他的一句代碼,我覺得超容易啊~~~下面我來說下具體操作:

首先看下我的成果:

1、控制項的布局

<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"    android:background="@drawable/bg"    tools:context=".MainActivity" > <TextView        android:id="@+id/txv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/tishi"        android:textColor="#D2691E"        android:textSize="20dp" />    <LinearLayout        android:id="@+id/linOut1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/txv"        android:orientation="horizontal" >        <Button            android:id="@+id/me"            android:layout_width="60dp"            android:layout_height="60dp"            android:layout_marginLeft="10dp"            android:layout_marginRight="20dp"            android:layout_marginTop="20dp"            android:layout_weight="1"            android:background="@drawable/niub" /></LinearLayout><LinearLayout        android:id="@+id/linOut_txt1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/linOut1"        android:orientation="horizontal" >        <TextView            android:id="@+id/txv1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="20dp"            android:layout_marginRight="10dp"            android:layout_weight="1"            android:text="@string/txv1" /></LinearLayout>

  2.代碼實現:

package com.example.phone;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity {private Button  niu;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);onclick();               niu.setOnClickListener(new BtnOnlick());    }    private void onclick() {        niu = (Button) findViewById(R.id.niu);    }    private class BtnOnlick implements View.OnClickListener {public void onClick(View v) {switch (v.getId()) {                        case R.id.niu:getIntent("##########");break;                        default:break;                    }               }    }    private void getIntent(String str) {Intent i_ling = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + str));startActivity(i_ling);}}                                                

  

這裡只用了一個Button 和 TextView,具體的大家自己添加哦~~~

3.設定許可權

開啟AndroidManifest.xml -----在application標籤上或者下面添加這麼一句代碼:<uses-permission android:name="android.permission.CALL_PHONE"/>

4.打包(有些要填的隨便填)

右鍵點擊項目-----Export-----Andriod-----Export...-----next---next-----

5.放在手機安裝運行。如想和我們進一步學習交流可加我的Andriod新手學習群:26040687,歡迎大家一起學習交流~~~~哈哈哈哈

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.