2012-09-17 52 views
2

我想使用html文件,我在部署它時做了它,它不會鍛鍊(輸入html頁面需要顯示,但它顯示當我部署時不可用的網頁)!錯誤消息也不在LOG中!請任何幫助。我在做什麼錯了?爲什麼html5功能在我的android應用程序中不起作用?

public class TestActivity extends Activity { 
    /** Called when the activity is first created. */ 
    WebView webView =null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     webView =(WebView)findViewById(R.id.web); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.setWebChromeClient(new WebChromeClient()); 
     webView.loadUrl("file:///android-assets/www/index.html"); 

    } 
} 

這裏是我的javascript。

function sayhello(){ 
alert("hi", document.getElementById('name'),value); 
} 

和HTML文件是在這裏

<!DOCTYPE html> 
<html> 
<head> 
<script src="index.js"></script> 
</head> 
<body> 
What is ur name ? 
<input id="name" value=""> 
<button onclick="sayhello()">say hello</button> 
</body> 
</head> 
</html> 

和佈局

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

    <WebView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/web" 
     android:text="@string/hello" 
     /> 

</LinearLayout> 
+2

「它不會鍛鍊」那究竟意味着什麼?應用程序不啓動,應用程序顯示空白屏幕,應用程序崩潰,手機爆炸? – zapl

+0

html頁面應該出現,但它不會來...爲什麼和我在哪裏做錯了? – Bamadeva

回答

1

您需要使用:

file:///android-asset/www/index.html 

剛剛擺脫的 's'

UPDATE:

您還可以使用頁面加載:

webView.loadDataWithBaseURL(null, html, "text/html", "utf-8",null); 

當第二個參數是你的頁面加載。

+0

仍然無法正常工作。資產是內置文件夾,爲什麼它應該是「資產」。或者是否有任何我需要提供的插件來處理html5。 – Bamadeva

+0

我無法在官方頻道上找到文章,但我已經使用了android_asset並可以正常工作。我用另一種可以嘗試的方法更新了我的答案。 – Neil

相關問題