2014-01-16 87 views
0

我想從asset文件夾加載。我試着跟蹤並搜索。但是,我的文件沒有加載。它說: 「沒有可用的Web頁」Html文件不能從資產文件夾加載

這裏是我的代碼: HelpActivity.java

public class HelpActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_help); 
    ((WebView) findViewById(R.id.webView1)) 
      .loadUrl("file///android_asset/help.html"); 
} 

public void closeWindow(View v) { 
    finish(); 
} 

} 

help.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".HelpActivity" > 

    <WebView 
     android:id="@+id/webView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

    </WebView> 

</LinearLayout> 

help.html

<html> 
<body> 
Hello world 
</body> 
</html> 

我應該包括在AndroidManifest任何權限?

回答

5

你從你的文件協議缺少:

file:///android_asset/help.html 
    ^
+3

相同的答案......你2秒快速所以要公平競賽,我刪除了我的:) – gunar

+1

@gunar現在這是很好的體育道德:) – CodingIntrigue

+0

正確的答案...另一個教程是有用的在http://lomza.people.totem-soft.com/?p=62 –

0
((WebView) findViewById(R.id.webView1)).loadUrl("file:///android_asset/help.html"); 
0
WebView mWebVwRehat = (WebView) findViewById(R.id.webView1; 
     mWebVwRehat.setBackgroundColor(0); // to make webview transparent 
     mWebVwRehat.loadUrl("file:///android_asset/help.html"); 
相關問題