android:用外部浏览器打开网址

一,代码

        //给按钮增加点击事件
        Button webButton = findViewById(R.id.webbutton);
        webButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = "https://www.baidu.com";
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
            }
        });

 

二,测试效果

posted @ 2025-05-01 09:23  刘宏缔的架构森林  阅读(36)  评论(0)    收藏  举报