第一步:新建一个Android工程命名为02.Phone目录结构如下图:

第二步:修改activity_main.xml布局文件代码如下:

<LinearLayout 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:orientation="vertical"    tools:context=".MainActivity" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/please_enter_phone_number" />    <EditText        android:id="@+id/et_phone"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:inputType="phone" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:onClick="call"        android:text="@string/call" /></LinearLayout>

strings.xml:

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">02.Phone</string>    <string name="action_settings">Settings</string>    <string name="hello_world">Hello world!</string>    <string name="please_enter_phone_number">请输入电话号码</string>    <string name="call">呼叫此号码</string></resources>

第三步:编写MianActivity类:

package cn.leigo.phone;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.EditText;public class MainActivity extends Activity {private EditText mPhoneEditText;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mPhoneEditText = (EditText) findViewById(R.id.et_phone);}public void call(View v) {String number = mPhoneEditText.getText().toString();if (!TextUtils.isEmpty(number)) {Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ number));startActivity(intent);}}}


最后在AndroidManifest.xml文件中添加权限:

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

运行工程查看效果图:


更多相关文章

  1. Android(安卓)Studio 在命令行编译工程
  2. aar文件的libs有其他jar文件,使用时的注意点
  3. java更改android文件权限--待验证
  4. android关于手机和3.0版本以上平板去标题问题
  5. 2011-03-29 15:30 android用于打开各种文件的intent【原创】
  6. Android计算文件夹大小、文件大小单位转换、删除文件夹及其内容
  7. Intent打开各种类型文件
  8. Android(安卓)安装文件.apk反编译

随机推荐

  1. 详解Node模块加载机制
  2. golang 发送post请求 其body中json对象使
  3. 秘籍:自学后端知识体系
  4. python入门教程12-02 (python语法入门之多
  5. android MediaPlayer深入分析
  6. ITIL 4:服务目录管理
  7. 年末最新整理:阿里、腾讯、字节、华为、百
  8. 消息队列为什么说它像漏斗?
  9. 年底报表做到哭泣?学会Excel融合分析,让你
  10. Android如何获取系统高度、标题栏和状态