1、界面效果图
2、AndroidManifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.tjp"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="7" />
- <application android:icon="@drawable/congsmall" android:label="@string/app_name">
- <activity android:name=".PhoneActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.CALL_PHONE"/>
- </manifest>
注册电话拨打服务<uses-permission android:name="android.permission.CALL_PHONE"/>
3、界面代码
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/mobilelable"
- />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/mobile"/><Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/buttonlabl"
- android:id="@+id/btncall"
- />
- </LinearLayout>
4、界面值定义strings.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="mobilelable">请输入手机号码</string>
- <string name="app_name">电话拨号器</string>
- <string name="buttonlabl">拨打</string>
- </resources>
5、activity
- package com.tjp;
- import android.app.Activity;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class PhoneActivity extends Activity {
- private EditText mobile;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button btncall=(Button)this.findViewById(R.id.btncall);
- mobile=(EditText)this.findViewById(R.id.mobile);
- btncall.setOnClickListener(new View.OnClickListener(){ //匿名内部类
- @Override
- public void onClick(View v) {
- String mobilemobileText=mobile.getText().toString();
- Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobileText));//拨打电话
- startActivity(intent);
- }
- });
- }
- }
【编辑推荐】