Android之路——第一个Android小程序(Android电话拨号器)
2011-01-21 13:00
453 查看
废话不说,直接贴代码:
首先是布局的代码:main.xml
接下来是String.xml的代码:
上面两个都是位于res里面的。
接下来是src里面的代码DialogActivity:
这个代码写完还是不能用的,因为没有授权,所以必须在androidManifest这个文件里面写:<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
下面是这个程序的截图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/02/618a05812937d88623359e3f62b7d8b4.jpg)
首先是布局的代码:main.xml
<?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/inputmobile" /> <EditText android:layout_width = "fill_parent" android:layout_height= "wrap_content" android:id = "@+id/mobile" /> <Button android:id="@+id/button" android:layout_height="wrap_content" android:text="@string/button" android:layout_width="wrap_content"> </Button> </LinearLayout>
接下来是String.xml的代码:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="inputmobile">请输入手机号:</string> <string name="app_name">电话拨号器</string> <string name = "button">拨打此号码</string> </resources>
上面两个都是位于res里面的。
接下来是src里面的代码DialogActivity:
package cn.jason.android; 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 DialogActivity extends Activity { /** Called when the activity is first created. */ @Override /** * 这个方法是重载自启动方法,在Application启动的时候自动触发 */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //调用到button按钮 Button button = (Button) findViewById(R.id.button); //为button按钮设置监听器,监听器类型是在本视图的监听器 button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //调用到编辑框的值 EditText editText = (EditText) findViewById(R.id.mobile); //新建一个intent对象,进行调用系统的打电话的方法,然后传递号码过去 Intent intent = new Intent(Intent.ACTION_CALL , Uri.parse("tel:" + editText.getText())); //相应事件 DialogActivity.this.startActivity(intent); } }); } }
这个代码写完还是不能用的,因为没有授权,所以必须在androidManifest这个文件里面写:<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
下面是这个程序的截图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/02/618a05812937d88623359e3f62b7d8b4.jpg)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/02/3e6c9e710fcab9f5c696d730c68edc55.jpg)
相关文章推荐
- Android之路——第一个Android小程序(Android电话拨号器)
- 第一个Android小程序——电话拨号器
- Android开发之路之二------第一个程序HelloWord
- 第一个android程序--HelloAndroid
- 第一个android程序
- android 开发自学 1天(使用Andriod ADT开发第一个程序Hello World)
- Android之路——第二个Android小程序(Android短信发送)
- 写给初学者03_android_第一个安卓程序
- Android 漫游之路------Android电话拨号器(点击事件的几种写法)、Android短信发送器
- 【Android】简单详细的安卓开发环境配置及运行第一个程序Helloworld
- Android入门(4) 开发第一个Android程序
- Android OpenGL ES: 第一个程序
- Android开发学习之三——第一个Android程序
- 我的第一个PhoneGap程序(Android)
- 跟我学Android之二 第一个程序
- 【Android开发笔记】3.编写第一个Android程序
- 搭建android开发环境,第一个android程序
- 安装Intellij,编译第一个android程序出错
- android开发第0.5步,跑起第一个Android程序
- Android深入探究笔记之一 -- 我的第一个 Android 程序,基于 Intent 的组件交互机制