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
<
WebView
xmlns:android
=
"http://schemas.android.com/apk/res/android"
2
android:id
=
"@+id/webviewHelp android:layout_width="
fill_parent"
3
android:layout_height
=
"fill_parent"
/>
- use this code in your activity onCreate() method:
1
WebView webview = (WebView) findViewById(R.id.webviewHelp);
2
webview.loadData(readTextFromResource(R.raw.help),
"text/html"
,
"utf-8"
);
01
private
String readTextFromResource(
int
resourceID)
02
{
03
InputStream raw = getResources().openRawResource(resourceID);
04
ByteArrayOutputStream stream =
new
ByteArrayOutputStream();
05
int
i;
06
try
07
{
08
i = raw.read();
09
while
(i != -
1
)
10
{
11
stream.write(i);
12
i = raw.read();
13
}
14
raw.close();
15
}
16
catch
(IOException e)
17
{
18
e.printStackTrace();
19
}
20
return
stream.toString();
21
}
Không có nhận xét nào:
Đăng nhận xét