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
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...