【.NET老猿轉Android系列】第一課打電話程式

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   os   ar   sp   

    <EditText        android:id="@+id/txtNumber"        android:layout_width="match_parent"        android:layout_height="80dp"        android:inputType="phone" >    </EditText>

上面的  +    表示在R中建立一個id變數

 

layout_width:match_parent是跟父節點一樣寬

 

height:80dp是高80個單位(跟像素不是一個東西,但是對初學者來說就那麼個意思就行了,詳情參照:http://blog.csdn.net/moruite/article/details/6028547)

inputType非常有用,決定調出的鍵盤中能輸入哪些東東,除了phone還有number、email等,更多類型,請參照圖形介面的TextFields,或者自己FQ看這個:http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ainputType 以及代碼中的:  http://developer.android.com/reference/android/text/InputType.html 

 

然後再擺一個Button,掛接下點擊事件,如下:

 

 1 public class DialOnClickListener implements OnClickListener { 2  3         @Override 4         public void onClick(View v) { 5             EditText txtNumber=(EditText)(MainActivity.this.findViewById(R.id.txtNumber)); 6             String strNumber=txtNumber.getText().toString();         7             strNumber="tel:"+strNumber; 8              9             10             Intent itt=new Intent();11             itt.setAction(Intent.ACTION_CALL);12             itt.setData(Uri.parse(strNumber));13             startActivity(itt);14 15             16         }17     }

需要注意的是Intent類,表示發起一個“意圖”的動作。

另外要訪問this指標,只能通過MainActivity.this去訪問主視窗的指標。

 

以上是核心組件,運行即可。

【.NET老猿轉Android系列】第一課打電話程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.