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

一、项目截图


二、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;
		}
		
	}
}

四、下载地址

源码下载地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值