如何使用 kotlin 将按钮与 android studio 中的网站链接

A.E*_*sam 6 android uri android-intent kotlin

我想将我的应用程序中的按钮与网站链接,因为当用户单击此按钮时,网站会在浏览器或应用程序中打开,我使用的是 kotlin 而不是 java,我该怎么做?:) 我尝试使用此代码:

bu1.setOnClickListener({
var gourl= Intent(this,Uri.parse("https://www.facebook.com/"))
startActivity(gourl)
})


 bu1.setOnClickListener({
var gourl= Intent(this,Uri.parse("https://www.facebook.com/"))
startActivity(gourl)
})

 bu1.setOnClickListener({
var gourl= Intent(this,Uri.parse("https://www.facebook.com/"))
startActivity(gourl)
})
Run Code Online (Sandbox Code Playgroud)

Bob*_*Bob 9

这样做:

    val url = "http://www.example.com"
    val i = Intent(Intent.ACTION_VIEW)
    i.data = Uri.parse(url)
    startActivity(i)
Run Code Online (Sandbox Code Playgroud)

或者像这样:

    val i = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"))
    startActivity(i)
Run Code Online (Sandbox Code Playgroud)