傻A与傻C之间 - Sabby(一个徘徊在傻A与傻C之间的人)

欢迎来到傻A与傻C之间的博客,开发人员请加 C#/Java编程交流群:26438718、96020642

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

学习了一个星期了,总算学会了TextView、EditView、Button等基本的控件,还有一点点布局的知识,然后佳哥(我的师傅)就叫我写一个打电话的东西,感觉很神奇,不过经过他的一句代码,我觉得超容易啊~~~下面我来说下具体操作:

首先看下我的成果:

1、控件的布局

<RelativeLayout 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:background="@drawable/bg"
    tools:context=".MainActivity" >

 <TextView
        android:id="@+id/txv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tishi"
        android:textColor="#D2691E"
        android:textSize="20dp" />

    <LinearLayout
        android:id="@+id/linOut1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/txv"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/me"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:layout_weight="1"
            android:background="@drawable/niub" />

</LinearLayout>

<LinearLayout
        android:id="@+id/linOut_txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/linOut1"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/txv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:text="@string/txv1" />

</LinearLayout>

  2.代码实现:

package com.example.phone;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	private Button  niu;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
		onclick();
               niu.setOnClickListener(new BtnOnlick());
    }

    private void onclick() {
        niu = (Button) findViewById(R.id.niu);
    }

    private class BtnOnlick implements View.OnClickListener {
		public void onClick(View v) {
			switch (v.getId()) {

                        case R.id.niu:
				getIntent("##########");
				break;
                        default:
				break;
                    }
               }
    }

    private void getIntent(String str) {
		Intent i_ling = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + str));
		startActivity(i_ling);
	}

}
                                                

  

这里只用了一个Button 和 TextView,具体的大家自己添加哦~~~

3.设置权限

打开AndroidManifest.xml -----在application标签上或者下面添加这么一句代码:<uses-permission android:name="android.permission.CALL_PHONE"/>

4.打包(有些要填的随便填)

右键点击项目-----Export-----Andriod-----Export...-----next---next-----

5.放在手机安装运行。如想和我们进一步学习交流可加我的Andriod新手学习群:26040687,欢迎大家一起学习交流~~~~哈哈哈哈

 

 

posted on 2013-03-24 21:34  sabby  阅读(1535)  评论(10编辑  收藏  举报