So let’s get started…
- first, embed an html file in the app resources. For this, create the
“raw” subfolder in “res” folder and add your HTML formatted file:
- use a WebView view in your layout file:
1<WebViewxmlns:android="http://schemas.android.com/apk/res/android"2android:id="@+id/webviewHelp android:layout_width="fill_parent"3android:layout_height="fill_parent"/>
- use this code in your activity onCreate() method:
where readTextFromResource is something like this:
1WebView webview = (WebView) findViewById(R.id.webviewHelp);2webview.loadData(readTextFromResource(R.raw.help),"text/html","utf-8");
01privateString readTextFromResource(intresourceID)02{03InputStream raw = getResources().openRawResource(resourceID);04ByteArrayOutputStream stream =newByteArrayOutputStream();05inti;06try07{08i = raw.read();09while(i != -1)10{11stream.write(i);12i = raw.read();13}14raw.close();15}16catch(IOException e)17{18e.printStackTrace();19}20returnstream.toString();21}
Không có nhận xét nào:
Đăng nhận xét