Monday, July 16, 2012

Android help screen dialog

This article provide a simple template to construct an android help screen dialog. The actual help contents are built into a HTML file to make it easier to be reused when the application is being ported across multiple platforms. The approach uses a WebView inside a Dialog. Help contents in a raw HTML file are loaded into the WebView when the help dialog is launched.

Help pages main activity

Help pages dialog

Create a simple layout to be used for help dialog. Just has an embedded webview inside a linearlayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:layout_height="wrap_content" >


Create a HTML file with your help contents. A contact support link can also be added if required using "mailto:" descriptor.
<a href="#feedback">Feedback</a>
<a name="about_apphelp" id="about_apphelp">
<h3>About AppHelp</h3>
AppHelp is a test application to demonstrate a help dialog.
<a name="feedback" id="feedback">
Any comments, feedback, suggestions on AppHelp please write to us using the link below.
<a href="">Contact support</a>

All we need to do now is read the contents of the HTML file into a string and load this data into the web view. Also, we need to handle the mailto: URL. Sample code to achieve this is listed below.
public void onCreate(Bundle savedInstanceState) {
   WebView help = (WebView)findViewById(;
   help.setWebViewClient(new WebViewClient(){
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
  MailTo mt = MailTo.parse(url);
  Intent intent = new Intent(android.content.Intent.ACTION_SEND);
  intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mt.getTo()});     
  intent.putExtra(Intent.EXTRA_SUBJECT, "AppHelp feedback");     
  mContext.startActivity(Intent.createChooser(intent, "Send feedback ..."));
  return true;
    return true;

   String helpText = readRawTextFile(R.raw.help_contents);
   help.loadData(helpText, "text/html; charset=utf-8", "utf-8");

private String readRawTextFile(int id) {
   InputStream inputStream = mContext.getResources().openRawResource(id);
   InputStreamReader in = new InputStreamReader(inputStream);
   BufferedReader buf = new BufferedReader(in);
   String line;
   StringBuilder text = new StringBuilder();
   try {
      while (( line = buf.readLine()) != null) 
   } catch (IOException e) {
     return null;
   return text.toString();

This example can be downloaded here.

Contact Form


Email *

Message *

Back to Top