-1

I am developing an android information app for farmers.Informations will be given in local indian language.I am using webview for that purpose.Informations are stored in html files.The problem is that the informtions which are in local language are not visible.How to solve this?

WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting reference to WebView of the activity_main layout
    mWebView = (WebView) findViewById(R.id.webview);

    // Loading an html page into webview
    mWebView.loadUrl("file:///android_asset/text.html");
}

Activity main

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res   /android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".MainActivity" >

    <WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/hello_world" />

    </RelativeLayout>

html file

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;" charset="UTF-8">
    <style>
    /** Specify a font named "MyFont",
    and specify the URL where it can be found: */
     @font-face {
                font-family: "MyFont";
                src: url('file:///android_asset/b.ttf');
            }
            h3 { font-family:"MyFont"}
        </style>
</head>
<body>
    <h3>
        ಪ್ರಶಾಂತ
    </h3>
</body>

  • Store your files like `text-xy.html` where xy is something like `en`, `in`, ... a 2 character short indicating the language. Then, basing on the current locale, load the corresponding file. – Phantômaxx Mar 30 '16 at 06:58

3 Answers3

0

You mean to say you want to show helloworld in regional language. For that you need to create res/values- folder. The android framework will automatically pick up the right language Details: http://developer.android.com/guide/topics/resources/localization.html

Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17
0

Below are couple of stackoverflow posts which might help you.

How to show local languages font.

How to use custom font with webview.

Community
  • 1
  • 1
Jayakrishnan Salim
  • 977
  • 1
  • 10
  • 24
0
Try this

add this statement to your onCreate().

mWebView.getSettings().setJavaScriptEnabled(true);


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting reference to WebView of the activity_main layout
    mWebView = (WebView) findViewById(R.id.webview);

    mWebView.getSettings().setJavaScriptEnabled(true);

    // Loading an html page into webview
    mWebView.loadUrl("file:///android_asset/text.html");
}
Pravin Fofariya
  • 346
  • 2
  • 11