版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37827702/article/details/77387735
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button1 = (Button) findViewById(R.id.button_1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com")); startActivity(intent); } });
}
在java文件中对按钮button1重写点击函数
指定了Intent的action是Intent.ACTION_VIEW,这是一个android系统内置的动作,常量值为android.intent.action.VIEW
然后通过Uri.parse()方法,将网址字符串解析成Uri的对象,再通过Intent的setData()将uri这个对象传进来