2011-07-28 29 views
1

我的代碼是在這裏 的java文件我們如何顯示位於資產中的html頁面?

package org.example.webviewdemo; 

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

public class WebViewDemo extends Activity { 

    private WebView webView; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     webView = (WebView) findViewById(R.id.webview_compontent); 
     webView.loadUrl("file://android_asset//faq.htm"); 
    } 

} 

xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 


<WebView 
    android:id="@+id/webview_compontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1.0" 
/> 

,但我不能讓網頁內容 faq.htm是在文件夾資產

請helpme

+1

你的代碼看起來不錯。嘗試一個項目>清理並重建 –

回答

4
webView = (WebView) findViewById(R.id.webView); 
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl("file:///android_asset/folderName/index.html"); 
+0

ohh其工作Mac感謝 –

+0

非常簡單和優雅。它很簡單。 – vbocan

0

我想這是回答。

file:// android_asset/...,其中...是您的 項目資產/目錄中的相對路徑。

How to get URI from an asset File?

+0

謝謝....................... –

0

您是否嘗試過使用Uri.fromFile(文件),並從getAssets(文件)。打開(文件名)?

+0

謝謝................ ............. –

相關問題