2012-04-13 38 views
0

我必須從服務器加載頁面index.php。我不想從我的項目中的資源文件夾加載本地文件,但它不起作用。Android Webview index.html從服務器加載xxx.jpg從本地

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().requestFeature(Window.FEATURE_PROGRESS); 
    final Activity _activity = this; 

    setContentView(R.layout.main); 

    webview = (WebView) findViewById(R.id.webview); 

    webview.setWebViewClient(new myWebViewClient()); 

    webview.getSettings().setRenderPriority(RenderPriority.HIGH); 
    webview.getSettings().setJavaScriptEnabled(true); 

    webview.getSettings().setAllowFileAccess(true); 
    webview.getSettings().setAppCacheEnabled(false); 
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 

    webview.loadUrl("http://192.168.0.11/mypage.php"); 

      webview.setWebViewClient(new myWebViewClient() { 
     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon)  { 
      // TODO Auto-generated method stub 
      super.onPageStarted(view, url, favicon); 
      progressBar.show(); 
     } 

     @Override 
     public void onReceivedError(WebView view, int errorCode, 
       String description, String failingUrl) { 
      // TODO Auto-generated method stub 
      super.onReceivedError(view, errorCode, description, failingUrl); 

     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      // TODO Auto-generated method stub 
      super.onPageFinished(view, url); 
      progressBar.dismiss(); 
     } 
    }); 
    } 

在我的HTML頁面,一些地方的圖像加載這樣的:

<img src="file:///android_asset/image.jpg" width="200"> 

但不顯示圖像。

你有什麼想法?

謝謝,

André。

+0

檢查你的'圖像名稱和。擴展名是.jpg,你確定嗎?並刪除寬度並測試它! ' – 2012-04-13 11:24:08

+0

圖片擴展是正確的,並且我沒有檢查大小...不起作用。 – 2012-04-13 11:53:45

回答

0

沒有必要給像文件完整路徑assets..if要顯示HTML文件和圖像都是在資產目錄的同一目錄THN JST給出文件名

<img id="loadimage" src="ic_launcher.png" height="100px" width="100px" /> 

ic_launcher.png文件在資產文件夾中

相關問題