1.创建一个Android工程,整体的目录如下图所示:

2.新建一个activity,取名为activity_title,activity_title.xml的代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#000000" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_margin="5dp"android:background="#545454"android:text="back"android:textColor="#fff"android:textSize="24sp" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="5dp"android:layout_weight="1"android:gravity="center"android:text="拨号键盘"android:textColor="#fff"android:textSize="24sp" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_margin="5dp"android:background="#545454"android:text="edit"android:textColor="#fff"android:textSize="24sp" /></LinearLayout>

3.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" ><include layout="@layout/activity_title" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center" ><TextViewandroid:id="@+id/tv_text1"android:layout_width="match_parent"android:layout_height="200dp"android:layout_gravity="center"android:text=""android:textColor="#000000"android:textSize="50dp" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#000000"android:orientation="horizontal" ><TextViewandroid:id="@+id/tv_text2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="50"android:gravity="center"android:text=""android:textColor="#fff"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_delete"android:layout_width="54dp"android:layout_height="wrap_content"android:background="#545454"android:onClick="deleteClick"android:text="del"android:textColor="#fff" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt_one"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="1"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_two"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="2"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_three"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="3"android:textSize="20sp" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt_four"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="4"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_five"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="5"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_six"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="6"android:textSize="20sp" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt_seven"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="7"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_eight"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="8"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_nine"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="9"android:textSize="20sp" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt_star"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="0dp"android:layout_weight="1"android:text="*"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_zero"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="0"android:textSize="20sp" /><Buttonandroid:id="@+id/bt_bottom"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="#"android:textSize="20sp" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt_function"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="功能" /><Buttonandroid:id="@+id/bt_call"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="拨号" /><Buttonandroid:id="@+id/bt_all"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="联系人" /></LinearLayout></LinearLayout>

4.MainActivity.java的代码如下所示:

package edu.cn.call;import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;public class MainActivity extends Activity {private TextView tv_text1;private TextView tv_text2;private Button bt_delete;private Button bt_zero;private Button bt_one;private Button bt_two;private Button bt_three;private Button bt_four;private Button bt_five;private Button bt_six;private Button bt_seven;private Button bt_eight;private Button bt_nine;private Button bt_star;private Button bt_bottom;private Button bt_call;private Button bt_all;private TextView tempText;private String all = "";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tv_text1 = (TextView) findViewById(R.id.tv_text1);tv_text2 = (TextView) findViewById(R.id.tv_text2);bt_delete = (Button) findViewById(R.id.bt_delete);bt_zero = (Button) findViewById(R.id.bt_zero);bt_one = (Button) findViewById(R.id.bt_one);bt_two = (Button) findViewById(R.id.bt_two);bt_three = (Button) findViewById(R.id.bt_three);bt_four = (Button) findViewById(R.id.bt_four);bt_five = (Button) findViewById(R.id.bt_five);bt_six = (Button) findViewById(R.id.bt_six);bt_seven = (Button) findViewById(R.id.bt_seven);bt_eight = (Button) findViewById(R.id.bt_eight);bt_nine = (Button) findViewById(R.id.bt_nine);bt_star = (Button) findViewById(R.id.bt_star);bt_bottom = (Button) findViewById(R.id.bt_bottom);bt_call = (Button) findViewById(R.id.bt_call);bt_all = (Button) findViewById(R.id.bt_all);// 由于我的API版本太低了,所以没有办法执行这个代码// ActionBar actionBar = getSupportActionBar();// if (actionBar != null) {// actionBar.hide();// }bt_zero.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_zero);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_one.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_one);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_two.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_two);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_three.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_three);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_four.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_four);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_five.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_five);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_six.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_six);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_seven.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_seven);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_eight.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_eight);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_nine.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_nine);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_star.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_star);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_bottom.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_bottom);all += tempText.getText().toString();tv_text1.setText(all);tv_text2.setText(all);}});bt_call.setOnClickListener(new OnClickListener() {public void onClick(View v) {tempText = (TextView) findViewById(R.id.bt_call);Intent intent = new Intent(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:" + tempText.getText().toString()));startActivity(intent);}});bt_all.setOnClickListener(new OnClickListener() {public void onClick(View v) {Intent intent = new Intent();intent.setAction(Intent.ACTION_VIEW);intent.setData(Contacts.People.CONTENT_URI);startActivity(intent);}});bt_delete.setOnClickListener(new OnClickListener() {public void onClick(View v) {all = all.substring(0, all.length() - 1);tv_text1.setText(all);tv_text2.setText(all);}});}
}

5.我的AndroidManifest.xml如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="edu.cn.call"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="4"android:targetSdkVersion="17" /><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name="edu.cn.call.MainActivity"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></manifest>

6.运行能够实现拨号功能,代码下载地址:http://download.csdn.net/download/qq_29656961/9979275。

Android实现键盘拨号相关推荐

  1. android 软键盘监听、隐藏、显示、点击空白处隐藏和Android KEYCODE 键值大全

    android 软键盘监听.隐藏.显示.点击空白处隐藏. textView.setOnKeyListener(new View.OnKeyListener() {@Overridepublic boo ...

  2. android 软键盘工具类,Android软键盘管理工具类

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? 一个软键盘管理类,单例模式实现的. /** * 类功能描述:软键盘管理界面 * */ public class Inpu ...

  3. Android软键盘遮挡的四种解决方案

    Android软键盘遮挡的四种解决方案 参考文章: (1)Android软键盘遮挡的四种解决方案 (2)https://www.cnblogs.com/jerehedu/p/4194125.html ...

  4. Android 软键盘弹出时布局内指定内容上移实现及问题解决

    Android 软键盘弹出时布局内指定内容上移实现及问题解决 参考文章: (1)Android 软键盘弹出时布局内指定内容上移实现及问题解决 (2)https://www.cnblogs.com/as ...

  5. Android 软键盘弹出时把布局顶上去,控件乱套解决方法

    Android 软键盘弹出时把布局顶上去,控件乱套解决方法 参考文章: (1)Android 软键盘弹出时把布局顶上去,控件乱套解决方法 (2)https://www.cnblogs.com/zhuj ...

  6. android 设置键盘弹出动画,Android实现键盘弹出界面上移的实现思路

    1.首先说一下思路: 基本就是结合layout中ScrollView视图和AndroidManifest.xml中activity中的android:windowSoftInputMode属性配置实现 ...

  7. android自定义数字键盘和字母键盘,Android自定义键盘的实现(数字键盘和字母键盘)...

    Android自定义键盘的实现(数字键盘和字母键盘) 发布时间:2020-09-04 03:18:48 来源:脚本之家 阅读:100 作者:浪淘沙xud 在项目中,产品对于输入方式会有特殊的要求,需要 ...

  8. android软键盘上推ui解决

    为什么80%的码农都做不了架构师?>>>    http://bbs.csdn.net/topics/340198955 android软键盘上推ui解决 good job 转载于: ...

  9. Android软键盘弹出引起的各种不适终极解决方案

    参考博客:Android软键盘弹出引起的各种不适终极解决方案 http://blog.csdn.net/itachi85/article/details/6596284 在这里做个笔记 如果不想让软键 ...

  10. android自定义键盘遮挡,Android软键盘遮挡的四种完美解决方案

    一.问题概述 在编辑框输入内容时会弹出软键盘,而手机屏幕区域有限往往会遮住输入界面,我们先看一下问题效果图: 输入用户名和密码时,系统会弹出键盘,造成系统键盘会挡住文本框的问题,如图所示: 输入密码时 ...

最新文章

  1. Archlinux 下的 VMWare Workstation 维护笔记
  2. STM32 定时器输出pwm的频率计算方法 PWM 频率检测方法 直流电机的位置控制
  3. (一)Java中的HashMap多线程死循环
  4. 基于Gsoap 的ONVIF C++ 库
  5. 【训练平台】mmdetection训练自己的标注数据, 以faster RCNN ,yolo为例子
  6. QT下使用MapX控件的问题以及Activex技术
  7. 小白学习一eNSP华为模拟器(3) 交换机基础配置 实验四VLAN 配置Trunk
  8. NFC怎么复制房卡_为了省门禁卡的钱,买了NFC读卡器,到底值不值
  9. 3DMAX零基础图文教程学习
  10. javascript实现中国地图
  11. 打包一个包含手表端应用的手机端APK应用—Ticwear
  12. DeFi 2.0的LaaS协议,重振DeFi赛道发展的关键
  13. 【猿如意】中的『XMind』工具详情介绍
  14. 【Creo5.0二次开发参数化】选择装配
  15. 本题要求实现一个判断素数的简单函数、以及利用该函数计算给定区间内素数和的函数。素数就是只能被1和自身整除的正整数。注意:1不是素数,2是素数。
  16. 不止SQL优化,数据库还有哪些优化大法?
  17. although 与 though 的区别
  18. c语言实现磁盘存储空间的分配和回收,操作系统磁盘管理 借鉴资料
  19. openFOAM学习笔记(一)—— C++基础
  20. 微信小程序之数据处理

热门文章

  1. 魅族MX5 如何进入开发者模式
  2. 木瓜奇迹洗服务器维护,木瓜奇迹各种职业+点法
  3. 数据可视化~matplotlib显示多个子图
  4. problem: ERROR cluster.YarnClientSchedulerBackend: Yarn application has already exited with state
  5. 运维基础——Zabbix:Lack of free swap space on Zabbix server
  6. 天下风云出我辈,一入江湖岁月催
  7. vnc repeater linux,远程桌面中转,基于 UltraVNC Repeater(中继器)的远程桌面服务搭建,用于复杂网络环境...
  8. Weighted Boxes Fusion 源码解析
  9. 3DsMax——竹篮制作
  10. 计算机打字200字,学打字的作文200字