- import android.app.Activity;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- private Button mCallButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mCallButton = (Button) findViewById(R.id.btn_call);
- mCallButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //打给联通客服10010
- Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:10010"));
- startActivity(intent);
- }
- });
- }
- // @Override
- // public boolean onCreateOptionsMenu(Menu menu) {
- // // Inflate the menu; this adds items to the action bar if it is present.
- // getMenuInflater().inflate(R.menu.main, menu);
- // return true;
- // }
- //
- // public void clickHandler(View source){
- // TextView tv = (TextView) findViewById(R.id.show);
- // tv.setText("你好!现在时间:" + new java.util.Date());
- // }
- }
activity_main.xml:
- <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:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/show"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:text="@string/hello_world" />
- <Button
- android:id="@+id/btn_click"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/show"
- android:text="点击我"
- android:onClick="clickHandler"/>
- <Button
- android:id="@+id/btn_call"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/btn_click"
- android:text="拨打电话"/>
- </RelativeLayout>
AndroidManifest.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.xiami.caipiao"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="18" />
- <uses-permission android:name="android.permission.CALL_PHONE"/>
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.xiami.caipiao.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>