webView = (WebView) findViewById(R.id.take_webview);
webView.getSettings()
.setUserAgentString("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0");
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new CustomWebClient());
Log.d("Feedback url is ", url);
// enable javascript
webView.loadUrl(url);
我已经使用了上述设置,它适用于非移动设备友好网址,但是当我使用移动设备友好网址时,网络视图就像桌面视图一样。 请帮我解决这个问题。
答案 0 :(得分:1)
webView.setWebChromeClient(new MyWebChromeClient());
private class MyWebChromeClient extends WebChromeClient {
// display alert message in Web View
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
// Log.d(LOG_TAG, message);
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
}
答案 1 :(得分:0)
尝试这些代码行。
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
progressDialog = new ProgressDialog(YOUR_ACTIVITY.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (progressDialog.isShowing() ) {
progressDialog.dismiss();
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(ContestActivity.this, "Error:" + description, Toast.LENGTH_SHORT).show();
}
});
webView.loadUrl("YOUR URL HERE");