【问题标题】:How to link button with website in android studio using kotlin如何使用 kotlin 在 android studio 中将按钮与网站链接
【发布时间】:2018-01-14 01:44:55
【问题描述】:

我想将我的应用程序中的按钮与网站链接,因为当用户单击此按钮时,网站会在浏览器或应用程序中打开,我使用的是 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)
})

【问题讨论】:

    标签: android android-intent uri kotlin


    【解决方案1】:

    这样做:

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

    或者像这样:

        val i = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"))
        startActivity(i)
    

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 1970-01-01
      • 2020-08-15
      • 2017-07-10
      • 2018-06-29
      • 2016-08-01
      • 2016-06-13
      • 2023-03-28
      • 2014-10-09
      相关资源
      最近更新 更多