標籤: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系列】第一課打電話程式