package com.lhp.basic;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button btnBaidu,call;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnBaidu=findViewById(R.id.btn_open_baidu);
call=findViewById(R.id.btn_call);
btnBaidu.setOnClickListener(new ButtonListener());
call.setOnClickListener(new ButtonListener());
}
//监听事件
private class ButtonListener implements View.OnClickListener{
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_call:
Intent intent= new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10086"));
startActivity(intent);
break;
case R.id.btn_open_baidu:
Intent intent1=new Intent(Intent.ACTION_VIEW);//设置Action
intent1.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent1);
break;
default:
finish();//关闭Acticty
}
}
}
}
网友评论