1、Main.axml文件:

<?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">
<EditText
android:inputType="phone"
android:layout_width="match_parent" //填充父控件大小
android:layout_height="wrap_content" //根据内容自动拉伸
android:id="@+id/etphoneNum" />
<Button
android:text="Button"
android:layout_width="100.0dp" //dp,与密度无关的像素,一种基于屏幕密度的抽象单位。在每英寸160点的显示器上,1dp="1px";
android:layout_height="wrap_content"
android:id="@+id/btnSend"
android:layout_marginRight="0.0dp" />
</LinearLayout>

2、Activity1.cs文件:

namespace AndroidDemo {

/// <summary>

/// 标签AndroidDemo将出现在Android应用程序窗口中;MainLauncher批注,其表明了Activity是应用程序的主要启动对象;Icon是程序图标

/// </summary>

[Activity(Label = "电话拨号器", MainLauncher = true, Icon = "@drawable/icon")]

public class Activity1 : Activity //activity活动,一个“活动”就是一个用来完成单个任务有的用户界面组件

{

EditText etphoneNum;

Button btnSend;

protected override void OnCreate(Bundle bundle)

{

base.OnCreate(bundle);//初始化资源包

// Set our view from the "main" layout resource

SetContentView(Resource.Layout.Main);//加载视图

btnSend = this.FindViewById<Button>(Resource.Id.btnSend);

etphoneNum = this.FindViewById<EditText>(Resource.Id.etphoneNum);

btnSend.Click += btnSend_Click;

}

void btnSend_Click(object sender, EventArgs e)

{

string phoneNum = etphoneNum.Text.Trim();

if (phoneNum.Length == 0)

{

Toast.MakeText(this, "请输入手机号", ToastLength.Long).Show();

return;

}

//Intent myIntent = new Intent();//创建一个意图

//myIntent.SetAction(Intent.ActionCall);//设置行为是“打电话”

//myIntent.SetData(Android.Net.Uri.Parse("tel:"+phoneNum));//设置数据,数据即为电话号码,注意格式:tel:123456***

var myIntent = new Intent(Intent.ActionCall,Android.Net.Uri.Parse("tel:"+phoneNum));

StartActivity(myIntent);//开始活动

}

}

}

3、最后,别忘设置权限,只有拥用CALL_PHONE权限才能实现拨打电话

可以右击“项目”,选择“属性”,即可打开Android Manifest清单,在Required permissions下选择“CALL_PHONE”即可。

<users-permission android:name="android.permission.CALL_PHONE"/>

更多相关文章

  1. android之应用程序退到android桌面的实现
  2. android 模拟器获取root权限
  3. android Mainifest权限设置清单
  4. android 笔记 --- Android应用程序的权限列表
  5. 获得Android Linux系统增删文件的权限
  6. 2、创建android应用程序
  7. Android UI LinearLayout权限级别与TableLayout混合使用,
  8. Android上的Adobe AIR应用程序运行环境发布了!
  9. 为什么 Android 截屏需要 root 权限

随机推荐

  1. IFL嵌入式小组技术博客入口导航
  2. Cannot add extension with name 'androi
  3. Android简明开发教程十六:Button 画刷示例
  4. android学习笔记20--------------Relativ
  5. android中wifi原理及流程分析(很经典)
  6. android 输入法弹出 标题栏不被顶出去
  7. Android系统中自带了很多图标,我们的程序
  8. Android内部存储和外部存储的几个概念(内
  9. ListView点击效果设置
  10. ibmdeveloper上的android 的文章