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" tools:context=".MainActivity" > <Button android:id="@+id/main_web" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="web" /> <Button android:id="@+id/main_tel" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="tel" /> </LinearLayout>
package com.example.demo0623; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; public class MainActivity extends Activity implements OnClickListener { private Button main_web, main_tel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 去掉标题 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); // 初始化控件 initView(); } private void initView() { // TODO Auto-generated method stub main_web = (Button) this.findViewById(R.id.main_web); main_tel = (Button) this.findViewById(R.id.main_tel); main_web.setOnClickListener(this); main_tel.setOnClickListener(this); } // 点击事件 @Override public void onClick(View arg0) { // 跳转到浏览器中打开baidu if (arg0.getId() == R.id.main_web) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com")); startActivity(intent); // 跳转到拨打号码页面 } else if (arg0.getId() == R.id.main_tel) { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:10086")); startActivity(intent); } } }
运行截图:
点击web
原文:http://blog.csdn.net/qingbowen/article/details/46609001