简体   繁体   English

打开本地HTML文件

[英]Opening a local HTML file

I have a textview in a layout (called - t_c) with the code:- 我在具有代码的布局(称为-t_c)中有一个textview:

      <TextView
      android:id="@+id/GoToTCContacting"
      android:layout_width="360dp"
      android:layout_height="wrap_content"
      android:layout_marginLeft="2dp"
      android:layout_marginRight="2dp"
      android:layout_weight="2"
      android:background="@drawable/border2"
      android:clickable="true"
      android:onClick="GoToTCContacting"
      android:padding="10dp"
      android:text="Contacting"
      android:textColor="#FFF"
      android:textSize="18sp" />

I want the textview to open another layout (called - t_c_contacting) on click which has a webview in and that webview to open a html file I have in my layout folder called con.html. 我希望textview在单击时打开另一个布局(称为-t_c_contacting),其中包含一个webview,并且该webview打开一个我在布局文件夹中名为con.html的html文件。

This is how the t_c_contacting layout is coded:- 这就是t_c_contacting布局的编码方式:-

 <WebView
 android:id="@+id/contactingView"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />

This is how my class is set up to open t_c_contacting which works fine but I can't work out how to populate the webview with my file. 这是我的班级设置为打开t_c_contacting的方式,该方法可以正常工作,但是我无法确定如何用我的文件填充Webview。

    public void GoToTCContacting(View view)  
{  
    setContentView(R.layout.t_c_contacting); 
}

If you already have the HTML stored localy, simply call: 如果您已经在本地存储了HTML,则只需调用:

webView.loadDataWithBaseURL(mUrl, mHtmlData, MIME_TYPE, CHARSET, "");

Where: 哪里:

mUrl can be a dummy Url if you want, or the actual URL of the page, so the WebView can figure out how to place some UI elements such as Images. 如果需要, mUrl可以是虚拟Url,也可以是页面的实际URL,因此WebView可以弄清楚如何放置一些UI元素,例如Images。

mHtmlData is a String that contains the actual HTML content. mHtmlData是一个包含实际HTML内容的字符串。

MIME_TYPE is a String that represents the mimeType of the data, say: "text/html" MIME_TYPE是一个String,代表数据的mimeType,例如: "text/html"

CHARSET is a String that represents the encoding of the data, say: "utf-8" CHARSET是一个字符串,代表数据的编码,例如: "utf-8"

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM