zoukankan      html  css  js  c++  java
  • Android的电话拨号器

    1.编写布局文件

        android:layout_width="fill_parent"

        android:layout_height="fill_parent" >

        <EditText

            android:id="@+id/et_number"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:inputType="phone" >

           

       

        <Button

            android:id="@+id/bt_dail"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentRight="true"

            android:layout_below="@+id/et_number"

            android:text="@string/dail" />

    2.编写java代码

    package com.itheima.phone;

    import android.app.Activity;

    import android.content.In

    tent;

    import android.net.Uri;

    import android.os.Bundle;

    import android.text.TextUtils;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.widget.Button;

    import android.widget.EditText;

    import android.widget.Toast;

    public class PhoneActivity extends Activity {

    private EditText dt_number = null;

    @Override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    Button bt_dail = (Button) this.findViewById(R.id.bt_dail);

    dt_number = (EditText) PhoneActivity.this.findViewById(R.id.et_number);

    bt_dail.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View v) {

    String number = dt_number.getText().toString().trim();

    if(TextUtils.isEmpty(number)) {

    Toast.makeText(PhoneActivity.this, "号码不能为空!", Toast.LENGTH_SHORT).show();

    return ;

    }

     Intent intent = new Intent();

    intent.setAction(Intent.ACTION_CALL);

    intent.setData(Uri.parse("tel:" + number));

    startActivity(intent);

    }

    });

    }

    }

    3.清单文件授权
  • 相关阅读:
    『Linux学习笔记』0. 在Windows中运行Linux内核(Ubuntu)
    『Linux学习笔记』10. 文本编辑器
    『Linux学习笔记』9. 进程
    九种乱码解决办法(非原创)
    Eclipse中10个最有用的快捷键组合
    MVC(Model View Controller)框架
    ognl表达式
    统计一段文字中数组、中文、英文字母、空格以及其他特殊字符出现的次数
    java基础知识4
    java基础知识3
  • 原文地址:https://www.cnblogs.com/freenovo/p/4469845.html
Copyright © 2011-2022 走看看