Web 视图未在 API 级别 19(KITKAT)中加载
Web View did not load in API Level 19(KITKAT)
我在 Android 中使用 webView 并尝试在 Android 中签入 API 级别大于或等于 19.My 代码适用于 API 级别大于 19,但 WebView 未在 API 级别 19.Can 中打开,请有人检查一下。
这是代码:
public boolean loadingFinished = true;//is loading finished
public boolean redirect = false;// redirect to page
/**
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.web_view, container, false);
mWebView = (WebView) rootView.findViewById(R.id.webView);
//initializing views
backButton = (BUtton) rootView.findViewById(R.id.web_view_back_button);
titleTextView = (TextView) rootView.findViewById(R.id.web_view_textView);
progressBar = (ProgressBar) rootView.findViewById(R.id.web_view_progress_bar);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
mWebView.setVisibility(View.GONE);//Visible the view after full loaded
mWebView.setInitialScale(1);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setScrollbarFadingEnabled(false);
//check for network connection if not available show error msg!!!
if (!NetworkService.getConnectivityInfo().isConnected(getContext())) {
progressBar.setVisibility(View.GONE);
Toast.makeText(getContext(), getContext().getString(R.string.no_network_msg), Toast.LENGTH_SHORT).show();
} else {
mWebView.loadUrl("https://www.google.co.in");
}
progressBar.setVisibility(View.VISIBLE);
mWebView.setWebViewClient(new WebViewClient() {
/**
* {@inheritDoc}
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;
view.loadUrl(urlNewString);
return true;
}
/**
* {@inheritDoc}
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadingFinished = false;
}
/**
* {@inheritDoc}
*/
@Override
public void onPageFinished(WebView view, String url) {
if (!redirect) {
loadingFinished = true;
}
if (loadingFinished && !redirect) {
progressBar.setVisibility(View.GONE);
//After page is loaded then whole web-view is visible
mWebView.setVisibility(View.VISIBLE);
} else {
redirect = false;
}
}
});
return rootView;
}
API19 中的 WebView 引擎发生了变化。
http://developer.android.com/guide/webapps/migrating.html
在 API 19 级函数 setInitialScale(int scaleInPercent) 没有 work.Thats 为什么代码 运行 在 API 大于 19 级上很好。删除后 mWebView.setInitialScale(1);
从我的代码来看,它在 API 级别 19 中也运行良好。
我在 Android 中使用 webView 并尝试在 Android 中签入 API 级别大于或等于 19.My 代码适用于 API 级别大于 19,但 WebView 未在 API 级别 19.Can 中打开,请有人检查一下。 这是代码:
public boolean loadingFinished = true;//is loading finished
public boolean redirect = false;// redirect to page
/**
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.web_view, container, false);
mWebView = (WebView) rootView.findViewById(R.id.webView);
//initializing views
backButton = (BUtton) rootView.findViewById(R.id.web_view_back_button);
titleTextView = (TextView) rootView.findViewById(R.id.web_view_textView);
progressBar = (ProgressBar) rootView.findViewById(R.id.web_view_progress_bar);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
mWebView.setVisibility(View.GONE);//Visible the view after full loaded
mWebView.setInitialScale(1);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setScrollbarFadingEnabled(false);
//check for network connection if not available show error msg!!!
if (!NetworkService.getConnectivityInfo().isConnected(getContext())) {
progressBar.setVisibility(View.GONE);
Toast.makeText(getContext(), getContext().getString(R.string.no_network_msg), Toast.LENGTH_SHORT).show();
} else {
mWebView.loadUrl("https://www.google.co.in");
}
progressBar.setVisibility(View.VISIBLE);
mWebView.setWebViewClient(new WebViewClient() {
/**
* {@inheritDoc}
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;
view.loadUrl(urlNewString);
return true;
}
/**
* {@inheritDoc}
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadingFinished = false;
}
/**
* {@inheritDoc}
*/
@Override
public void onPageFinished(WebView view, String url) {
if (!redirect) {
loadingFinished = true;
}
if (loadingFinished && !redirect) {
progressBar.setVisibility(View.GONE);
//After page is loaded then whole web-view is visible
mWebView.setVisibility(View.VISIBLE);
} else {
redirect = false;
}
}
});
return rootView;
}
API19 中的 WebView 引擎发生了变化。 http://developer.android.com/guide/webapps/migrating.html
在 API 19 级函数 setInitialScale(int scaleInPercent) 没有 work.Thats 为什么代码 运行 在 API 大于 19 级上很好。删除后 mWebView.setInitialScale(1);
从我的代码来看,它在 API 级别 19 中也运行良好。