gpt4 book ai didi

java - 如何使用 Java 在 Android Studio 的 WebView 中提供网站链接?

转载 作者:行者123 更新时间:2023-12-01 20:21:50 25 4
gpt4 key购买 nike

在我的应用程序中,我想在 WebView 中提供链接。怎么给呢?我的链接是“http://www.google.com ”,使用 Android Studio 和 Java。这里我的链接是一个“http”链接,意思是外部链接。想法表示赞赏!!!

最佳答案

我不知道您想用该 WebView 做什么,但我建议您在应用程序中使用手机 Web 浏览器而不是 WebView。

Android 中的 Activity 是独立的 Android 组件,要连接它们,您可以使用 Intent 对象。这样,您可以在应用程序内创建新 Activity ,也可以启动第三方 Activity 。在本例中,是网络浏览器。尝试此代码并告诉我这是否可以解决您的问题

 Uri uri = Uri.parse("https://google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

并确保每次使用 URL 时始终键入 https://或 http://。

关于java - 如何使用 Java 在 Android Studio 的 WebView 中提供网站链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58934571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com