2

I want to add some html files in different languages in my application for supporting my application for different languages. I have done with string.xml file but now i want to add html pages on web view according to device language. How can i do this?

Thanks in advance

Veger
  • 37,240
  • 11
  • 105
  • 116
unflagged.destination
  • 1,576
  • 3
  • 19
  • 38

1 Answers1

1

Lets say you want to store your HTML files in /res/string, then you can use language qualifiers to specify for which language the resources is meant, like /res/string-en or /res/string-nl (for English respectively Dutch files).

Same goes for all other resource types, like /res/drawable, /res/raw/, etc.

For more information checkout the Android Localization pages.

To load the HTML from a string and show it in your WebView use the loadData() method:

html = resources.getString(R.string.my_html_page);
myWebView.loadData(html, "text/html", myEncoding);
Veger
  • 37,240
  • 11
  • 105
  • 116
  • OK. I have created the raw folder for different languages, now i am trying to load the html files in web view but don't know how to add the path of these html files in WebView.loadUrl() function? i have used mainHelpWebView.loadUrl(getResources().getString(R.raw.help_main)); and also mainHelpWebView.loadDataWithBaseURL(getResources().getString(R.raw.help_main), null, null, null, null); but both are not working – unflagged.destination Jan 05 '13 at 10:55
  • But it loads the string. I have the html files in the raw folder and want to load these files in web view according to device language. – unflagged.destination Jan 05 '13 at 11:13
  • http://stackoverflow.com/questions/4087674/android-read-text-raw-resource-file shows how to read the file content of a `raw` resource. – Veger Jan 05 '13 at 11:22
  • I sorted with this problem with WebView.loadUrl("file:///android_res/raw/fileName.html"); – unflagged.destination Jan 05 '13 at 11:44