2013-02-03 19 views
0

如何使用意圖加載靜態html字符串?使用意圖加載靜態html?

下面的代碼會導致運行時錯誤:

  public void onClick(View v) 
       { 
       String html = "<html><pre>this is text</pre></html>"; 
       Uri uri = Uri.parse(html); 
       startActivity(new Intent(Intent.ACTION_VIEW, uri)); 
+0

你必須在webview中加載頁面。 – GrIsHu

+0

使用webview ... – smk

回答

0

試着在WebView如下加載文本:

WebView browser; 
String html = "<html><pre>this is text</pre></html>"; 
browser=(WebView)findViewById(R.id.webkit);  
browser.loadData(html, "UTF-8"); 
0

下面是一個完整的代碼引用。我已經嘗試過,它的工作原理。
Android意圖應用程序加載HTML網頁。 Uri.parse(URL)

/activity_main.xml 使用創建按鈕

<Button 

     android:layout_width="wrap_content" 

     android:layout_height="wrap_content" 

     android:text="@string/intro" 

     android:onClick="load" /> 

那麼方法

public void load (View view) { 
String url = "http://www.fullchipdesign.com/verilog.htm"; 
Intent intent= new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(url)); 
startActivity(intent); 

} 

完全使用這個鏈接 http://www.fullchipdesign.com/tyh/android_app_list_intent_html.htm宣佈MainActivity.java