2012-09-17 56 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

相关问题