您的位置:首页 > 移动开发 > Android开发

黑马66期android学习笔记14-电话拨号器定义布局&获取组件对象

2015-07-22 09:14 671 查看
一、项目截图



二、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"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:paddingLeft="10dp"
android:text="@string/send_news"
/>
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/bohao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bohao"
/>
</LinearLayout>


三、MainActivity.java代码

package com.example.dialer;

import java.util.logging.Logger;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends ActionBarActivity implements OnClickListener{
private static final String TAG="MainActivity";
private EditText editText;
private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editText=(EditText) findViewById(R.id.phone);
button=(Button) findViewById(R.id.bohao);
button.setOnClickListener(this);
}

@Override
public void onClick(View v) {

switch (v.getId()) {
case R.id.bohao:
String number=editText.getText().toString();
Log.i(TAG,"执行了拨打电话:"+number);
/**
* 告诉系统,拨打电话
* */
//1、创建Intent
Intent intent=new Intent();
//2、告诉系统动作
intent.setAction(Intent.ACTION_CALL);
//3.打电话数据
intent.setData(Uri.parse("tel:"+number));
//4.启动该动作
startActivity(intent);

break;

default:
break;
}

}
}


四、下载地址

源码下载地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: