Tag Archive: webview

RTL support on android

Hola everyone,
Long time no see :D I was making an app based on hebrew language. Its true that hebrew is not fully supported on all android phones. On some device it may work RTL and on some hebrew won’t be supported at all. Anyway here i am again to share something that i learned. On devices that supported hebrew(rendering) had a minor issue, lets say there is a number 52 on a hebrew sentence and when u try to display this sentence then 52 number is displayed reverse i.e 25. Now just imagine how messed up will whole sentence be because of this reverse number. Thus i found loophole in new android RTL support. So i had to do something about it as this was full hebrew language based app. I was using textview to display this hebrew sentence and this sentence was coming from xml web service. So i came up with my awesome solution. I chose to use webview to render/display hebrew sentence with html formatting. SO my code looked like this to prepare html:

public static String BuildHtml(String hebrewText)
{       
StringBuilder sb = new StringBuilder();
sb.append(“<html>”);
sb.append(“<meta http-equiv=\”Content-Type\” content=\”text/html;charset=utf-8\”>”);
sb.append(“<body style=\”direction:rtl;\”>”);
sb.append(“<font color=#000000>”);
sb.append(hebrewText.trim());
sb.append(“</body>”);
sb.append(“</html>”);
       
return sb.toString();
}

Now i load my html on a webview by calling my method that returns my hebrew string encoded in html format.

webView.loadData(BuildHtml(myHebrewText), “text/html”, “utf-8″);

This code worked flawlessly. The number 56 was getting displayed as 56 in a hebrew sentence.
I hope this helps those who faced simillar problem.

Gracias.

Dude where is my javascript ?

Hola everyone,
a very hectic schedule going on this season. Working my ass off in my upcoming ambitious project. Anyway i am here and writing about just very basic problem that i faced. For a game project i wanted to show leaderboards, for this part i decided to use web view to show leaderboards page optimized for device. It has some javascript function that is doing its stuff of retrieving leaderboards details and all that. So i wrote a line to load the url pointing to my leaderboard page and guess what it didn’t rendered fully and i was again left scratching my head :D . Then after going through many testing i found that stuffs that were dependent on javascript were not getting rendered on my web view so i got the root of the problem i.e dude where is my javascript ? . Then i did a peroid(.) operator on my webview reference variable and found a method setJavaScriptEnabled(), so i did something like this:

webView.getSettings().setJavaScriptEnabled(true);

and yeah u guessed it right, it rendered fully after calling that method. So i guess by default javascript is disabled on webview. Phew.

Gracias.