Working on Power Schedule, I wanted to make a short help file, with some formatting. It seems there were several ways of doing this, but I chose to include an embedded HTML file into my application. It seemed easier to just edit an HTML file in an editor.
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:
    Add raw HTML file
  • use a WebView view in your layout file:
    	<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    		android:id="@+id/webviewHelp android:layout_width="fill_parent"
    		android:layout_height="fill_parent"/>
    
  • use this code in your activity onCreate() method:
    		WebView webview = (WebView) findViewById(R.id.webviewHelp);
    		webview.loadData(readTextFromResource(R.raw.help), "text/html", "utf-8");
    

    where readTextFromResource is something like this:

    	private String readTextFromResource(int resourceID)
    	{
    		InputStream raw = getResources().openRawResource(resourceID);
    		ByteArrayOutputStream stream = new ByteArrayOutputStream();
    		int i;
    		try
    		{
    			i = raw.read();
    			while (i != -1)
    			{
    				stream.write(i);
    				i = raw.read();
    			}
    			raw.close();
    		}
    		catch (IOException e)
    		{
    			e.printStackTrace();
    		}
    		return stream.toString();
    	}
    

It will look something like this:
HTML file on Android

I hope it helps :)