WebView

来源:http://www.cnblogs.com/520-1314/archive/2016/01/29/5169334.html
-Advertisement-
Play Games

前人經驗: 開源控制項:一個自定義的帶數字progress類:NumberProgressBar; WebViewClient就是幫助WebView處理各種通知、請求事件的。 WebChromeClient是輔助WebView處理Javascript的對話框,網站圖標,網站title,載入進度等 。


前人經驗:

開源控制項:一個自定義的帶數字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);
}
});

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.
  • 介紹了幾種清除浮動的方法
  • HTML5定稿了,終於有一種編程語言開發的程式可以在Android和IOS兩種設備上運行了 本文轉載自: http://www.cnblogs.com/tuyile006/p/4103634.html(只作轉載, 不代表本站和博主同意文中觀點或證實文中信息) 2007 年 W3C (萬維網聯盟)立項
  • 一篇不錯的資源博文,轉載分享給大家: 1、Android團隊提供的示例項目 如果不是從學習Android SDK中提供的那些樣例代碼開始,可能沒有更好的方法來掌握在Android這個框架上開發。由Android的核心開發團隊提供了15個優秀的示例項目,包含了游戲、圖像處理、時間顯示、開始菜單快捷方式
  • 一、weak和strong 1.理解 剛開始學UI的時候,對於weak和strong的描述看得最多的就是“由ARC引入,weak相當於OC中的assign,但是weak用於修飾對象,但是他們都不會造成引用計數加1;而strong則相當於OC中規定retain,它會造成引用計數加1”。 ARC的原理:
  • 觸摸事件 iOS中的事件: 在用戶使用app過程中,會產生各種各樣的事件。iOS中的事件可以分為3大類型: view的觸摸事件處理: 響應者對象: 在iOS中不是任何對象都能處理事件,只有繼承了UIResponder的對象才能接收並處理事件。我們稱之為“響應者對象”。 UIApplication、U
  • 第一組UI組件:佈局管理器(以ViewGroup為基類派生的佈局管理器) 1.線性佈局 LinearLayout類 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:orienta
  • 原理:轉場動畫push pop 菜單控制器做成左邊不透明一部分右邊透明,代碼里複製了之前控制器的視圖會在這裡顯示 菜單和菜單詳情是用的兩個不同的轉場動畫實現的 效果圖 demo鏈接:http://pan.baidu.com/s/1c0TaHDu
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...