目前分類:WEBVIEW (31)

瀏覽方式: 標題列表 簡短摘要

gWcMp.png  

I have used this example to test this code and confirm it works. In this example the qualibus.swf is in contained within the assets of the app. Please test this on an actual device, as on the emulator it show a blank page (probably the flash player is not present on the emulator)

Test3Activity.java:

package com.blabla.test3; 

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class Test3Activity extends Activity {

戮克 發表在 痞客邦 留言(0) 人氣()

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

<!DOCTYPE html>

<html lang="ko">
    <head>
        <title>Hello World</title>
        <meta charset="utf-8"/>

        <script type="text/javascript">
            function selectEvent(selectObj) 
            {
                alert(selectObj.value+" 所選的選擇");
            }
        </script>
    </head>
    <body>

        <select onchange="selectEvent(this)">
            <option value="a1">1小時</option>
            <option value="a2">2小時</option>
<option value="a3">3小時</option>
<option value="a4">4小時</option>
<option value="a5">5小時</option>
<option value="a6">6小時</option>
<option value="a7">7小時</option>
<option value="a8">8小時</option>
        </select>

        <button value="a9" onclick="selectEvent(this)">按一下</button>

    </body>
</html>

 

 

 

戮克 發表在 痞客邦 留言(0) 人氣()

需要建立webview用的layout

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="HTTP://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>




戮克 發表在 痞客邦 留言(0) 人氣()

NSHTTPCookie *cookie;

NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];

NSArray *cookieAry = [cookieJar cookiesForURL: [NSURL URLWithString@"http://api.m.taobao.com"]];

for (cookie in cookieAry) {

[cookieJar deleteCookie: cookie];

}


戮克 發表在 痞客邦 留言(0) 人氣()

最近帮一个同学做一个项目,断断续续的一些知识点记录一下。一个页面中有一个WebView,用来播放swf,如果系统中未安装flash插件,必须提示用户到market中安装。

下面做一个demo,效果图如下:

首先布局文件,很简单:

 

[html] view plaincopy
 
 
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.     <WebView  
  6.         android:id="@+id/webview"   
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="fill_parent"  
  9.         android:layout_centerInParent="true" />  
  10. </RelativeLayout>  

戮克 發表在 痞客邦 留言(0) 人氣()

div 需設定css overflow:auto 及-webkit-overflow-scrolling:touch

<div id="wrapper" style="width: 100%; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch;">

 

<iframe id="stupid-iframe" width="600" height="200" src="test.html"></iframe>
</div>

戮克 發表在 痞客邦 留言(0) 人氣()

為了讓返回按鈕控制WebView“返回上一頁”,我處理了按鈕消息並加入相關邏輯。同時為了復用WebView,我需要在特定的時候調用WebView::clearHistory() ,不料WebView::clearHistory()並未起作用。

 

原因是WebView::clearHistory()有個奇怪的特性,那就是只清除當前頁之前的歷史記錄。假設當前頁面為A,我調用WebView::clearHistory()然後loadUrl(B),接著回退還是會退到A。所以正確的調用時機是在B完全載入之後才行,簡單的解決方案:

 

1
2
3
4
5
6
7
8

戮克 發表在 痞客邦 留言(0) 人氣()

第一、初始化

 

1._webView=[[UIWebView alloc] initWithFrame:CGRectOffset(self.view.bounds, 020)];
2._webView.delegate=self;
3.NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
4.[_webView loadRequest:request];
5.[self.view addSubview:_webView];

戮克 發表在 痞客邦 留言(0) 人氣()

public class BrowserTest extends Activity {

  private WebView mWebView;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  mWebView = new WebView(this);

  mWebView.getSettings().setJavaScriptEnabled(true);

  mWebView.getSettings().setPluginsEnabled(true);

  mWebView.loadUrl("http://m.kongregate.com/games/Jiggmin/the-game-of-disorientation-mobile");

  setContentView(mWebView);

戮克 發表在 痞客邦 留言(0) 人氣()

当我们在使用WebView时,如果加载的网友比较大,这加载速度将非常慢。

现总结几种加速WebView加载的方法
1、提高渲染的优先级
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
2、使用webView.getSettings().setBlockNetworkImage,把图片加载放在最后来加载渲染。参照示例1.
3,使用硬件加速,该功能在Android 3.0 (API level 11)才加入。具体参照http://developer.android.com/guide/topics/graphics/hardware-accel.html
示例1:
 
  1. package com.robin;  
  2.  
  3.  
  4. import com.robin.R;  
  5. import android.app.Activity;  
  6. import android.app.Dialog;  
  7. import android.app.ProgressDialog;  
  8. import android.content.Context;  
  9. import android.content.DialogInterface;  
  10. import android.os.Bundle;  
  11. import android.os.Handler;  
  12. import android.os.Message;  
  13. import android.util.Log;  
  14. import android.view.View;  
  15. import android.view.Window;  
  16. import android.webkit.DownloadListener;  
  17. import android.webkit.WebChromeClient;  
  18. import android.webkit.WebSettings;  
  19. import android.webkit.WebSettings.RenderPriority;  
  20. import android.webkit.WebView;  
  21. import android.widget.Button;  
  22. import android.widget.Toast;  
  23.  
  24.  
  25. /**  
  26.  * @author Administrator  
  27.  *   
  28.  */ 
  29. public class MyActivity extends Activity {  
  30. private WebView webView;  
  31. final static String TAG = "MyActivity";  
  32. Handler handler = new Handler();  
  33. boolean blockLoadingNetworkImage=false;  
  34. //static long t=0;  
  35. //static long t1=0;  
  36. String link;  
  37. protected void onCreate(Bundle savedInstanceState) {  
  38. super.onCreate(savedInstanceState);  
  39. link = getIntent().getStringExtra("url");  
  40. setContentView(R.layout.news_details);  
  41.  
  42.  
  43. webView = (WebView) findViewById(R.id.webView);  
  44. webView.getSettings().setBuiltInZoomControls(true);  
  45. webView.getSettings().setJavaScriptEnabled(true);  
  46. webView.getSettings().setRenderPriority(RenderPriority.HIGH);  
  47. webView.getSettings().setBlockNetworkImage(true);  
  48. blockLoadingNetworkImage=true;  
  49. webView.setWebChromeClient(new WebChromeClient() {  
  50. public void onProgressChanged(WebView view, int progress) {  
  51. // Activities and WebViews measure progress with different  
  52. // scales.  
  53. // The progress meter will automatically disappear when we reach  
  54. // 100%  
  55. //Log.i(TAG, "progress:" + progress);  
  56. if(loadingProgressDialog!=null&&loadingProgressDialog.isShowing())  
  57. loadingProgressDialog.setProgress(progress);  
  58. if (progress >= 100) {  
  59. /*if(t==0)  
  60. t=System.currentTimeMillis()-t1;  
  61. else  
  62. t=(t+System.currentTimeMillis()-t1)>>1;  
  63. t1=System.currentTimeMillis()-t1;  
  64. Log.i(TAG, "t:" + t/1000+" t1:"+t1/1000);*/ 
  65. if(blockLoadingNetworkImage)  
  66. {  
  67. webView.getSettings().setBlockNetworkImage(false);  
  68. blockLoadingNetworkImage=false;  
  69. }  
  70. if (loadingProgressDialog!=null&&loadingProgressDialog.isShowing())  
  71. dismissDialog(PROGRESS_DIALOG_CONNECTING);  
  72. }  
  73. }  
  74. });  
  75. Runnable r = new Runnable() {  
  76. public void run() {  
  77. webView.loadUrl(link);  
  78. //t1=System.currentTimeMillis();  
  79. Log.i(TAG, "url:" + link);  
  80. showDialog(PROGRESS_DIALOG_CONNECTING);  
  81. }  
  82. };  
  83. handler.postDelayed(r, 200);  
  84.  
  85.  
  86. }  
  87.  
  88.  
  89. protected void onResume() {  
  90. super.onResume();  
  91. if (webView.getProgress() < 100)  
  92. showDialog(PROGRESS_DIALOG_CONNECTING);  
  93. }  
  94.  
  95.  
  96. protected void onDestroy() {  
  97. webView.stopLoading();  
  98. webView.destroy();  
  99. super.onDestroy();  
  100. }  
  101.  
  102.  
  103. final static int PROGRESS_DIALOG_CONNECTING = 1000;  
  104. ProgressDialog loadingProgressDialog = null;  
  105.  
  106.  
  107. @Override 
  108. protected Dialog onCreateDialog(int id) {  
  109. switch (id) {  
  110. case PROGRESS_DIALOG_CONNECTING: {  
  111. ProgressDialog progressDialog = new ProgressDialog(this);  
  112. progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);  
  113. progressDialog.setMessage(getResources()  
  114. .getString(R.string.loading));  
  115. loadingProgressDialog = progressDialog;  
  116. return progressDialog;  
  117. }  
  118. default:  
  119. break;  
  120. }  
  121. return null;  
  122. }  
  123.  
  124.  
  125. protected void onPrepareDialog(int id, Dialog dialog) {  
  126. super.onPrepareDialog(id, dialog);  
  127. switch (id) {  
  128. case PROGRESS_DIALOG_CONNECTING: {  
  129. loadingProgressDialog.setMax(100);  
  130. dialog.show();  
  131. }  
  132. break;  
  133. default:  
  134. break;  
  135. }  
  136. }  
  137.  
  138.  

來源:http://hunankeda110.iteye.com/blog/1807839


戮克 發表在 痞客邦 留言(0) 人氣()

如显示图片:

 
 
<img src="" id="myimg"/>
 
<script>
var url = document.location.href.substring(0,document.location.href.indexOf(window.document.location.pathname)) + document.location.pathname.substring(0,document.location.pathname.lastIndexOf("/")+1);
var imgurl=url+"myimg.png";
document.getElementById("myimg").src=imgurl;
</script>
 



设置背景图片:

 
 
var url = document.location.href.substring(0,document.location.href.indexOf(window.document.location.pathname)) + document.location.pathname.substring(0,document.location.pathname.lastIndexOf("/")+1);
document.body.style.backgroundImage="url('"+url+"mybackground.png')";
 

戮克 發表在 痞客邦 留言(0) 人氣()

«12