我想在WebView中打开以下链接
https://tickets.musiconelive.com/admin/SACValidateBarcode.asp
我正在使用以下代码来执行此操作
web=(WebView)findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("https://tickets.musiconelive.com/admin/SACValidateBarcode.asp");
但它没有在WebView中打开,而是在浏览器中打开。
如何解决此问题?
答案 0 :(得分:9)
这可以帮助你
WebSettings mWebSettings;
WebView mWebView = (WebView)findViewById(R.id.services_detail_magnified_image);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
mWebView.setBackgroundColor(Color.TRANSPARENT);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_INSET);
mWebView.loadUrl(StaticURL.uChangePassword);
mWebView.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
@Override
//show the web page in webview but not in web browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl (url);
return true;
}
}
答案 1 :(得分:3)
我认为这会对你有所帮助。
package com.adySol;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
public class adySol extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url ="http://tickets.musiconelive.com/admin/SACValidateBarcode.asp";
WebView wv=(WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(PluginState.ON);
wv.getSettings().setAllowFileAccess(true);
wv.loadUrl(url);
}
}
Main.xml ::
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
>
<WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent"></WebView>
</LinearLayout>
明确许可:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
答案 2 :(得分:0)
您需要设置WebViewClient()
This is example in kotlin
webview.apply {
loadUrl("https://www.google.com/")
webViewClient = WebViewClient()
}
根据android文档 public void setWebViewClient(WebViewClient客户端) 设置将接收各种通知和请求的WebViewClient。这将替换当前的处理程序。
答案 3 :(得分:-1)
webView=findViewById(R.id.webView);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR)
webView.setBackgroundColor(Color.TRANSPARENT);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_INSET);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.setWebViewClient(MyWebViewClient());
webView.loadUrl("https://google.com/");
class MyWebViewClient extends WebViewClient() {
@override
boolean shouldOverrideUrlLoading(WebView view , WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request)
}
}