【发布时间】:2019-03-08 09:53:46
【问题描述】:
在我的应用程序中,我有一些 TextView,其中包含指向某些网站的链接。目前,当用户点击它们时,网站正在默认浏览器(如 Chrome)中打开,但我想强制它们在我的应用程序中的 webview 中打开。能做到吗?
【问题讨论】:
在我的应用程序中,我有一些 TextView,其中包含指向某些网站的链接。目前,当用户点击它们时,网站正在默认浏览器(如 Chrome)中打开,但我想强制它们在我的应用程序中的 webview 中打开。能做到吗?
【问题讨论】:
你需要创建一个 web view Activity/Fragment。
您可以在布局中定义小部件
<WebView
android:id="@+id/myWebview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
然后从您的活动中打开选定的链接
WebView myWebView = findViewById(R.id.myWebview);
myWebView.loadUrl("http://www.example.com");
【讨论】:
browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(browserIntent); 的 Intent 开始新活动
尝试设置WebViewClient。
webView.setWebViewClient(new WebViewClient());
【讨论】: