码迷,mamicode.com
首页 > Web开发 > 详细

WebView

时间:2016-01-29 20:07:54      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

前人经验:

开源控件:一个自定义的带数字progress类:NumberProgressBar

 

 

WebViewClient就是帮助WebView处理各种通知、请求事件的。

WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等 。

总结:别把简单的东西复杂化。

NumberProgressBar.java

 

我的网盘:http://share.weiyun.com/cfda31dae65609c7376d0f9153678a27

 

style

 

<style name="NumberProgressBar_Funny_Orange">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>

<item name="progress_max">100</item>
<item name="progress_current">0</item>

<item name="progress_unreached_color">@android:color/transparent</item>
<item name="progress_reached_color">#f00722</item>
<item name="progress_text_size">10sp</item>
<item name="progress_text_color">#f00722</item>

<item name="progress_reached_bar_height">1.5dp</item>
<item name="progress_unreached_bar_height">0.75dp</item>
</style>

 

 

xml布局

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/ticket_web"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
<com.etoury.project.ui.view.NumberProgressBar
android:id="@+id/progressbar"
style="@style/NumberProgressBar_Funny_Orange"
android:layout_width="match_parent"
app:progress_reached_bar_height="2dp"
app:progress_text_size="0sp"
app:progress_text_visibility="invisible"
app:progress_unreached_bar_height="2dp" />

</FrameLayout>

java代码

pr = (NumberProgressBar) findViewById(R.id.progressbar);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setBlockNetworkImage(false);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setBlockNetworkLoads(false);
webView.getSettings().setGeolocationEnabled(true);
String url = "http://u.ctrip.com/union/CtripRedirect.aspx?TypeID=650&city="
+"北京"+"&cityid=1&sourceid=1&sid=777206&allianceid=303851&ouid=";
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.setVisibility(View.VISIBLE);
super.onPageFinished(view, url);
}

@Override
public void onLoadResource(WebView view, String url) {
if (url.contains("https://accounts.ctrip.com/H5Login/") || url.contains("http://m.ctrip.com/you/place/1")
|| url.contains("http://m.ctrip.com/webapp/diyshx/list/") || url.contains("http://m.ctrip.com/webapp/Hotel/hotel1")) {
view.stopLoading();
}
super.onLoadResource(view, url);
}
});
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
super.onGeolocationPermissionsShowPrompt(origin, callback);
callback.invoke(origin, true, false);


}

@Override
public void onProgressChanged(WebView view, int newProgress) {
if (pr == null) return;
pr.setProgress(newProgress);
if (newProgress == 100) {
pr.setVisibility(View.GONE);
} else {
pr.setVisibility(View.VISIBLE);
}
super.onProgressChanged(view, newProgress);
}
});

 

WebView

标签:

原文地址:http://www.cnblogs.com/520-1314/p/5169334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!